infiniflow/ragflow · error · RuntimeError
Tenant not found!
Error message
Tenant not found!
What it means
Raised in FileService.delete_docs when DocumentService.get_tenant_id(doc_id) returns falsy for a document that was just fetched. It means the document row exists but its tenant cannot be resolved (join to tenant/kb failed), so ownership cannot be verified before deletion proceeds.
Source
Thrown at api/db/services/file_service.py:718
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)
doc_parser = doc.parser_id
if doc_parser == ParserType.TABLE:
kb_id = doc.kb_idView on GitHub (pinned to 554fb1133a)
Solutions
- Inspect the document row's kb_id and trace it to the knowledge base and tenant tables; repair or remove the orphaned row.
- If the parent dataset was deleted concurrently, refresh the document list and skip this id.
- Run the deletion again after fixing referential integrity.
- Avoid manual deletes that bypass DocumentService, which can create such orphans.
Defensive patterns
Strategy: try-catch
Validate before calling
tenant_id = DocumentService.get_tenant_id(doc_id)
if not tenant_id:
skip_or_quarantine(doc_id) # orphaned document, do not hard-delete blindly Try / catch
try:
FileService.delete_docs([doc_id], tenant_id)
except RuntimeError as e:
if 'Tenant not found' in str(e):
quarantine_orphaned_document(doc_id)
raise Prevention
- Never delete knowledge bases or tenants with raw SQL; use the service APIs so documents stay consistent.
- Periodically check for documents whose kb_id has no matching knowledgebase row.
- Avoid racing dataset deletion with document deletion in automation.
When it happens
Trigger: A document row whose kb_id/tenant_id references a deleted knowledge base or tenant; data restored partially; concurrent deletion of the parent KB between get_by_id and get_tenant_id.
Common situations: Orphaned documents left by older bugs or manual DB surgery; deleting documents right as their dataset is being removed in another session.
Related errors
- Exist more than 1 user: {username}!
- Failed to get skill folder ID
- Failed to get version folder ID
- Space ID is required
- Skill not found
AI-assisted analysis of infiniflow/ragflow@554fb1133a (2026-08-15).
Data as JSON: /api/errors/9b8ca2560026e042.
Report an issue: GitHub.