Fix: Handle NoneType error when processing documents without a file path

The document processing pipeline would crash with a TypeError when a document was submitted as raw text via the API, as the file_path attribute would be None. This change adds a check to handle the None case gracefully, preventing the crash and allowing text-based documents to be indexed correctly.
This commit is contained in:
Anton Vice 2025-07-08 19:35:22 -03:00
parent 1497f334f6
commit b192f8c9a3

View File

@ -900,9 +900,15 @@ class LightRAG:
# Get first document's file path and total count for job name
first_doc_id, first_doc = next(iter(to_process_docs.items()))
first_doc_path = first_doc.file_path
path_prefix = first_doc_path[:20] + (
"..." if len(first_doc_path) > 20 else ""
)
# Handle cases where first_doc_path is None
if first_doc_path:
path_prefix = first_doc_path[:20] + (
"..." if len(first_doc_path) > 20 else ""
)
else:
path_prefix = "unknown_source"
total_files = len(to_process_docs)
job_name = f"{path_prefix}[{total_files} files]"
pipeline_status["job_name"] = job_name