{"record":{"id":"bff38b421e4ccbad","repo":"langgenius/dify","slug":"file-not-found-bff38b","errorCode":null,"errorMessage":"File not found.","messagePattern":"File not found\\.","errorType":"http","errorClass":"NotFound","httpStatus":404,"severity":"error","filePath":"api/controllers/console/datasets/datasets_document.py","lineNumber":731,"sourceCode":"            raise DocumentAlreadyFinishedError()\n\n        data_process_rule = document.get_dataset_process_rule(session=session)\n        data_process_rule_dict: Mapping[str, Any] = data_process_rule.to_dict() if data_process_rule else {}\n\n        if document.data_source_type == \"upload_file\":\n            data_source_info = document.data_source_info_dict\n            if data_source_info and \"upload_file_id\" in data_source_info:\n                file_id = data_source_info[\"upload_file_id\"]\n\n                file = session.scalar(\n                    select(UploadFile)\n                    .where(UploadFile.tenant_id == document.tenant_id, UploadFile.id == file_id)\n                    .limit(1)\n                )\n\n                # raise error if file not found\n                if not file:\n                    raise NotFound(\"File not found.\")\n\n                extract_setting = ExtractSetting(\n                    datasource_type=DatasourceType.FILE, upload_file=file, document_model=document.doc_form\n                )\n\n                indexing_runner = IndexingRunner()\n\n                try:\n                    estimate_response = indexing_runner.indexing_estimate(\n                        tenant_id=current_tenant_id,\n                        extract_settings=[extract_setting],\n                        tmp_processing_rule=data_process_rule_dict,\n                        doc_form=document.doc_form,\n                        doc_language=\"English\",\n                        dataset_id=dataset_id_str,\n                        session=session,\n                    )\n                    return (","sourceCodeStart":713,"sourceCodeEnd":749,"githubUrl":"https://github.com/langgenius/dify/blob/ef8544b173fd6cd7a8e71df2cab576e52bebbfbc/api/controllers/console/datasets/datasets_document.py#L713-L749","documentation":"werkzeug NotFound (HTTP 404) raised in GET .../documents/{document_id}/indexing-estimate when document.data_source_type == 'upload_file' but the UploadFile row referenced by data_source_info.upload_file_id does not exist for the document's tenant. The underlying file backing the document is gone.","triggerScenarios":"Estimate on an upload_file document whose UploadFile row was deleted (storage cleanup, retention expiry, manual deletion) before the estimate call.","commonSituations":"File retention policy purged UploadFile rows; tenant data cleanup; orphaned document pointing at a removed file; cross-tenant file_id confusion.","solutions":["Re-upload the source file and recreate the document, then request the estimate.","Delete the orphan document so it stops surfacing in the UI.","Audit UploadFile retention / cleanup settings so future files persist for the document lifetime.","Restore from backup if the file is irreplaceable."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"import requests\n\ndef upload_file_exists(base_url, headers, tenant_id, upload_file_id) -> bool:\n    # there is no direct public lookup; infer from document detail\n    r = requests.get(f\"{base_url}/console/api/datasets/{dataset_id}/documents/{document_id}\",\n                     headers=headers)\n    r.raise_for_status()\n    doc = r.json()\n    return bool(doc.get('data_source_info', {}).get('upload_file_id'))\n\n# call estimate only when the file reference is intact\nif not upload_file_exists(base, hdrs, tenant_id, upload_file_id):\n    raise SystemExit('backing UploadFile missing; re-upload or remove the orphan document')","typeGuard":"def has_intact_upload_file(doc: dict) -> bool:\n    return bool(doc.get('data_source_info', {}).get('upload_file_id'))","tryCatchPattern":"try:\n    r = requests.get(f\"{base}/console/api/datasets/{dataset_id}/documents/{document_id}/indexing-estimate\",\n                     headers=hdrs)\n    r.raise_for_status()\nexcept requests.HTTPError as e:\n    if e.response.status_code == 404 and 'File not found' in e.response.text:\n        # mark document as orphan for cleanup; do not retry estimate\n        orphan_documents.add(document_id)\n    else:\n        raise","preventionTips":["Set UploadFile retention to outlive the document lifetime.","Run periodic consistency checks for orphaned documents.","Don't manually DELETE UploadFile rows while documents reference them.","Treat 510 as terminal for that document; re-upload or remove."],"tags":["upload-file","storage","not-found","datasets","estimate"],"backgroundTag":null,"analyzedSha":"ef8544b173fd6cd7a8e71df2cab576e52bebbfbc","analyzedAt":"2026-08-12T05:15:17.394Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}