infiniflow/ragflow · warning · RuntimeError
document not found
Error message
document not found
What it means
Raised in FileService.delete_docs when DocumentService.get_by_id(doc_id) returns not-found for one of the submitted document ids. The per-doc try block catches it and appends it to the errors string returned to the caller, so one bad id does not abort the whole batch.
Source
Thrown at api/db/services/file_service.py:715
@staticmethod
def put_blob(user_id, location, blob):
bname = f"{user_id}-downloads"
return settings.STORAGE_IMPL.put(bname, location, blob)
@classmethod
@DB.connection_context()
def delete_docs(cls, doc_ids, tenant_id):
root_folder = FileService.get_root_folder(tenant_id)
pf_id = root_folder["id"]
FileService.init_knowledgebase_docs(pf_id, tenant_id)
errors = ""
kb_table_num_map = {}
for doc_id in doc_ids:
try:
e, doc = DocumentService.get_by_id(doc_id)
if not e:
raise RuntimeError("document not found")
tenant_id = DocumentService.get_tenant_id(doc_id)
if not tenant_id:
raise RuntimeError("Tenant not found!")
b, n = File2DocumentService.get_storage_address(doc_id=doc_id)
TaskService.filter_delete([Task.doc_id == doc_id])
if not DocumentService.remove_document(doc, tenant_id):
raise RuntimeError("Database error (Document removal)!")
f2d = File2DocumentService.get_by_document_id(doc_id)
deleted_file_count = 0
if f2d:
deleted_file_count = FileService.filter_delete([File.source_type == FileSource.KNOWLEDGEBASE, File.id == f2d[0].file_id])
File2DocumentService.delete_by_document_id(doc_id)
if deleted_file_count > 0:
settings.STORAGE_IMPL.rm(b, n)
View on GitHub (pinned to 554fb1133a)
Solutions
- Treat the returned error text as per-file: remove the stale id from the request and re-submit the remainder.
- Before deleting, verify each id with DocumentService.get_by_id or the document-list API.
- Make deletion idempotent in your client: treat 'document not found' as success.
- Check for duplicate ids in the payload.
Example fix
# before FileService.delete_docs(['doc1', 'doc1'], tenant_id) # second lookup fails # after FileService.delete_docs(list(dict.fromkeys(doc_ids)), tenant_id) # dedupe
Defensive patterns
Strategy: try-catch
Validate before calling
doc_ids = list(dict.fromkeys(doc_ids)) # dedupe valid_ids = [d for d in doc_ids if DocumentService.get_by_id(d)[0]]
Try / catch
errors, _ = FileService.delete_docs(doc_ids, tenant_id)
if 'not found' in errors:
# treat as already-deleted: idempotent success
pass Prevention
- Make client-side deletion idempotent: 'not found' means already deleted.
- Deduplicate id lists before submitting batch deletes.
- Refresh document lists after deletions instead of reusing stale ids.
When it happens
Trigger: Calling the document deletion API with a doc id that was already deleted, belongs to another tenant, or is malformed; duplicate ids in the list where the first delete removes the doc and the second lookup fails.
Common situations: Stale document id in the UI after deletion in another tab; retrying a partially completed delete request; scripts re-running against an already-cleaned dataset.
Related errors
- User '{username}' not found
- Database error (Document removal)!
- main() returned a non-JSON-serializable value.
- Space ID is required
- Skill not found
AI-assisted analysis of infiniflow/ragflow@554fb1133a (2026-08-15).
Data as JSON: /api/errors/98b4e435a9955ea5.
Report an issue: GitHub.