Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

fix: batch delete document db session block (#32062)

Jyong4430a1b3da49
diff --git a/api/services/dataset_service.py b/api/services/dataset_service.py
index 1ea6c4e1c3e..b208e394b0e 100644
--- a/api/services/dataset_service.py
+++ b/api/services/dataset_service.py
@@ -1696,13 +1696,18 @@ class DocumentService:
for document in documents
if document.data_source_type == "upload_file" and document.data_source_info_dict
]
- if dataset.doc_form is not None:
- batch_clean_document_task.delay(document_ids, dataset.id, dataset.doc_form, file_ids)
+ # Delete documents first, then dispatch cleanup task after commit
+ # to avoid deadlock between main transaction and async task
for document in documents:
db.session.delete(document)
db.session.commit()
+ # Dispatch cleanup task after commit to avoid lock contention
+ # Task cleans up segments, files, and vector indexes
+ if dataset.doc_form is not None:
+ batch_clean_document_task.delay(document_ids, dataset.id, dataset.doc_form, file_ids)
+
@staticmethod
def rename_document(dataset_id: str, document_id: str, name: str) -> Document:
assert isinstance(current_user, Account)