[PR #32041] fix: metadata batch edit silently fails due to split transactions and swallowed exceptions #33520

Closed
opened 2026-02-21 20:53:26 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/langgenius/dify/pull/32041

State: closed
Merged: Yes


Summary

Fixes #31964 - Metadata batch edit doesn't work. When batch editing document metadata, nothing happens because the backend silently succeeds even when the update actually fails.

Root causes identified:

  • Split transaction in backend: The update_documents_metadata method committed doc_metadata JSON update and metadata binding management in two separate db.session.commit() calls. If the second commit failed (e.g., database error), the bindings were lost while the JSON was already committed, leaving data inconsistent -- doc_metadata_details (which joins via bindings) returned nothing even though the JSON had values.
  • Silent exception swallowing: The except Exception clause caught all errors and only logged them, while the API still returned {"result": "success"}. The frontend showed a success toast, but nothing was actually updated.
  • Unclean frontend payload: The frontend sent extra frontend-only fields (updateType, isUpdated, isMultipleValue) to the backend and could send undefined values instead of null.

Changes:

  • Combine doc_metadata JSON update and binding management into a single atomic transaction so they succeed or fail together
  • Add db.session.rollback() in the except block and re-raise exceptions so errors propagate to the API response (500) instead of being silently swallowed
  • Sanitize metadata items sent to the backend to only include id, name, type, value (with undefined coerced to null)

close #32094
close #32113
close #32225

Test plan

  • All existing backend unit tests pass (test_metadata_partial_update.py -- 3 tests)
  • All existing frontend unit tests pass (use-batch-edit-document-metadata.spec.ts -- 25 tests)
  • All batch edit modal component tests pass (132 tests across 7 spec files)
  • ESLint, Ruff, and TypeScript type-check pass
  • Manual test: select multiple documents, batch edit metadata values, verify changes persist
  • Manual test: verify error toast appears when batch edit actually fails (instead of false success)
**Original Pull Request:** https://github.com/langgenius/dify/pull/32041 **State:** closed **Merged:** Yes --- ## Summary Fixes #31964 - Metadata batch edit doesn't work. When batch editing document metadata, nothing happens because the backend silently succeeds even when the update actually fails. **Root causes identified:** - **Split transaction in backend**: The `update_documents_metadata` method committed `doc_metadata` JSON update and metadata binding management in two separate `db.session.commit()` calls. If the second commit failed (e.g., database error), the bindings were lost while the JSON was already committed, leaving data inconsistent -- `doc_metadata_details` (which joins via bindings) returned nothing even though the JSON had values. - **Silent exception swallowing**: The `except Exception` clause caught all errors and only logged them, while the API still returned `{"result": "success"}`. The frontend showed a success toast, but nothing was actually updated. - **Unclean frontend payload**: The frontend sent extra frontend-only fields (`updateType`, `isUpdated`, `isMultipleValue`) to the backend and could send `undefined` values instead of `null`. **Changes:** - Combine `doc_metadata` JSON update and binding management into a single atomic transaction so they succeed or fail together - Add `db.session.rollback()` in the except block and re-raise exceptions so errors propagate to the API response (500) instead of being silently swallowed - Sanitize metadata items sent to the backend to only include `id`, `name`, `type`, `value` (with `undefined` coerced to `null`) close #32094 close #32113 close #32225 ## Test plan - [x] All existing backend unit tests pass (`test_metadata_partial_update.py` -- 3 tests) - [x] All existing frontend unit tests pass (`use-batch-edit-document-metadata.spec.ts` -- 25 tests) - [x] All batch edit modal component tests pass (132 tests across 7 spec files) - [x] ESLint, Ruff, and TypeScript type-check pass - [x] Manual test: select multiple documents, batch edit metadata values, verify changes persist - [x] Manual test: verify error toast appears when batch edit actually fails (instead of false success)
yindo added the pull-request label 2026-02-21 20:53:26 -05:00
yindo closed this issue 2026-02-21 20:53:26 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#33520