{"record":{"id":"0284eb8e5f278d7f","repo":"langgenius/dify","slug":"document-not-found-0284eb","errorCode":null,"errorMessage":"Document not found.","messagePattern":"Document not found\\.","errorType":"http","errorClass":"NotFound","httpStatus":404,"severity":"error","filePath":"api/controllers/console/datasets/datasets_segments.py","lineNumber":724,"sourceCode":"        self,\n        req_data: ChildChunkCreatePayload,\n        session: Session,\n        current_tenant_id: str,\n        current_user: Account,\n        dataset_id: UUID,\n        document_id: UUID,\n        segment_id: UUID,\n    ):\n        # check dataset\n        dataset_id_str = str(dataset_id)\n        dataset = DatasetService.get_dataset(dataset_id_str, session)\n        if not dataset:\n            raise NotFound(\"Dataset not found.\")\n        # check document\n        document_id_str = str(document_id)\n        document = DocumentService.get_document(dataset_id_str, document_id_str, session=session)\n        if not document:\n            raise NotFound(\"Document not found.\")\n        if not current_user.is_dataset_editor:\n            raise Forbidden()\n        try:\n            DatasetService.check_dataset_permission(dataset, current_user, session)\n        except services.errors.account.NoPermissionError as e:\n            raise Forbidden(str(e))\n        # check embedding model setting\n        if dataset.indexing_technique == IndexTechniqueType.HIGH_QUALITY:\n            try:\n                model_manager = ModelManager.for_tenant(tenant_id=current_tenant_id)\n                model_manager.get_model_instance(\n                    tenant_id=current_tenant_id,\n                    provider=dataset.embedding_model_provider,\n                    model_type=ModelType.TEXT_EMBEDDING,\n                    model=dataset.embedding_model,\n                )\n            except LLMBadRequestError:\n                raise ProviderNotInitializeError(","sourceCodeStart":706,"sourceCodeEnd":742,"githubUrl":"https://github.com/langgenius/dify/blob/ef8544b173fd6cd7a8e71df2cab576e52bebbfbc/api/controllers/console/datasets/datasets_segments.py#L706-L742","documentation":"Raised after the dataset check passes but DocumentService.get_document returns None for the (dataset_id, document_id) pair. The document is not part of the dataset, was deleted, or the id is wrong; the controller returns NotFound.","triggerScenarios":"POST .../segments/{segment_id}/child_chunks with a document_id that is not a child of the given dataset, was deleted, or is malformed.","commonSituations":"Document was removed after the page was loaded; cross-dataset document id reused from another context; document is in a 'paused' or filtered state that hides it.","solutions":["List documents under the dataset to confirm the document_id belongs to it.","If the document was deleted, choose an existing document or re-upload it.","Reload the document tree in the UI before performing child-chunk operations."],"exampleFix":"// before\nPOST /datasets/{ds}/documents/{deleted_doc}/segments/{seg}/child_chunks\n// after\nGET /datasets/{ds}/documents -> pick existing document_id\nPOST /datasets/{ds}/documents/{existing_doc}/segments/{seg}/child_chunks","handlingStrategy":"validation","validationCode":"async function ensureDocument(datasetId, documentId) {\n  const r = await fetch(`/console/api/datasets/${datasetId}/documents/${documentId}`);\n  if (!r.ok) throw new Error('document not found under dataset');\n  return r.json();\n}","typeGuard":"const isValidDocumentId = (id) => typeof id === 'string' && /^[0-9a-fA-F-]{36}$/.test(id);","tryCatchPattern":"try {\n  await ensureDocument(datasetId, documentId);\n  await createChildChunk({...});\n} catch (e) { if (e.status === 404) throw new Error('reload document and retry'); throw e; }","preventionTips":["Always read the document_id from the dataset's document list, not from memory.","Disable the editor when the parent document disappears.","Re-fetch the document after long-lived edit sessions."],"tags":["datasets","child-chunk","document","not-found","rest-api"],"backgroundTag":null,"analyzedSha":"ef8544b173fd6cd7a8e71df2cab576e52bebbfbc","analyzedAt":"2026-08-12T05:15:17.394Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}