Anton Vice commited on
Commit
eef8ffa
·
1 Parent(s): 05a9e1a

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

Browse files

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.

Files changed (1) hide show
  1. lightrag/lightrag.py +9 -3
lightrag/lightrag.py CHANGED
@@ -900,9 +900,15 @@ class LightRAG:
900
  # Get first document's file path and total count for job name
901
  first_doc_id, first_doc = next(iter(to_process_docs.items()))
902
  first_doc_path = first_doc.file_path
903
- path_prefix = first_doc_path[:20] + (
904
- "..." if len(first_doc_path) > 20 else ""
905
- )
 
 
 
 
 
 
906
  total_files = len(to_process_docs)
907
  job_name = f"{path_prefix}[{total_files} files]"
908
  pipeline_status["job_name"] = job_name
 
900
  # Get first document's file path and total count for job name
901
  first_doc_id, first_doc = next(iter(to_process_docs.items()))
902
  first_doc_path = first_doc.file_path
903
+
904
+ # Handle cases where first_doc_path is None
905
+ if first_doc_path:
906
+ path_prefix = first_doc_path[:20] + (
907
+ "..." if len(first_doc_path) > 20 else ""
908
+ )
909
+ else:
910
+ path_prefix = "unknown_source"
911
+
912
  total_files = len(to_process_docs)
913
  job_name = f"{path_prefix}[{total_files} files]"
914
  pipeline_status["job_name"] = job_name