langgenius/dify · error · NotFound

File not found.

Error message

File not found.

What it means

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.

Source

Thrown at api/controllers/console/datasets/datasets_document.py:731

            raise DocumentAlreadyFinishedError()

        data_process_rule = document.get_dataset_process_rule(session=session)
        data_process_rule_dict: Mapping[str, Any] = data_process_rule.to_dict() if data_process_rule else {}

        if document.data_source_type == "upload_file":
            data_source_info = document.data_source_info_dict
            if data_source_info and "upload_file_id" in data_source_info:
                file_id = data_source_info["upload_file_id"]

                file = session.scalar(
                    select(UploadFile)
                    .where(UploadFile.tenant_id == document.tenant_id, UploadFile.id == file_id)
                    .limit(1)
                )

                # raise error if file not found
                if not file:
                    raise NotFound("File not found.")

                extract_setting = ExtractSetting(
                    datasource_type=DatasourceType.FILE, upload_file=file, document_model=document.doc_form
                )

                indexing_runner = IndexingRunner()

                try:
                    estimate_response = indexing_runner.indexing_estimate(
                        tenant_id=current_tenant_id,
                        extract_settings=[extract_setting],
                        tmp_processing_rule=data_process_rule_dict,
                        doc_form=document.doc_form,
                        doc_language="English",
                        dataset_id=dataset_id_str,
                        session=session,
                    )
                    return (

View on GitHub (pinned to ef8544b173)

Solutions

  1. Re-upload the source file and recreate the document, then request the estimate.
  2. Delete the orphan document so it stops surfacing in the UI.
  3. Audit UploadFile retention / cleanup settings so future files persist for the document lifetime.
  4. Restore from backup if the file is irreplaceable.
Defensive patterns

Strategy: validation

Validate before calling

import requests

def upload_file_exists(base_url, headers, tenant_id, upload_file_id) -> bool:
    # there is no direct public lookup; infer from document detail
    r = requests.get(f"{base_url}/console/api/datasets/{dataset_id}/documents/{document_id}",
                     headers=headers)
    r.raise_for_status()
    doc = r.json()
    return bool(doc.get('data_source_info', {}).get('upload_file_id'))

# call estimate only when the file reference is intact
if not upload_file_exists(base, hdrs, tenant_id, upload_file_id):
    raise SystemExit('backing UploadFile missing; re-upload or remove the orphan document')

Type guard

def has_intact_upload_file(doc: dict) -> bool:
    return bool(doc.get('data_source_info', {}).get('upload_file_id'))

Try / catch

try:
    r = requests.get(f"{base}/console/api/datasets/{dataset_id}/documents/{document_id}/indexing-estimate",
                     headers=hdrs)
    r.raise_for_status()
except requests.HTTPError as e:
    if e.response.status_code == 404 and 'File not found' in e.response.text:
        # mark document as orphan for cleanup; do not retry estimate
        orphan_documents.add(document_id)
    else:
        raise

Prevention

When it happens

Trigger: Estimate on an upload_file document whose UploadFile row was deleted (storage cleanup, retention expiry, manual deletion) before the estimate call.

Common situations: File retention policy purged UploadFile rows; tenant data cleanup; orphaned document pointing at a removed file; cross-tenant file_id confusion.

Related errors


AI-assisted analysis of langgenius/dify@ef8544b173 (2026-08-12). Data as JSON: /api/errors/bff38b421e4ccbad. Report an issue: GitHub.