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.

chore: skip document segments fetching with non-existed dataset of DatasetDocument in add_document_to_index_task task (#17784)

Bowen Liang636a0ba37f70
diff --git a/api/tasks/add_document_to_index_task.py b/api/tasks/add_document_to_index_task.py
index 0b7d2ad31fd..be88881efc6 100644
--- a/api/tasks/add_document_to_index_task.py
+++ b/api/tasks/add_document_to_index_task.py
@@ -37,6 +37,10 @@ def add_document_to_index_task(dataset_document_id: str):
indexing_cache_key = "document_{}_indexing".format(dataset_document.id)
try:
+ dataset = dataset_document.dataset
+ if not dataset:
+ raise Exception(f"Document {dataset_document.id} dataset {dataset_document.dataset_id} doesn't exist.")
+
segments = (
db.session.query(DocumentSegment)
.filter(
@@ -77,11 +81,6 @@ def add_document_to_index_task(dataset_document_id: str):
document.children = child_documents
documents.append(document)
- dataset = dataset_document.dataset
-
- if not dataset:
- raise Exception("Document has no dataset")
-
index_type = dataset.doc_form
index_processor = IndexProcessorFactory(index_type).init_index_processor()
index_processor.load(dataset, documents)