Skip to content

Commit 364ae23

Browse files
authored
Merge pull request #1891 from danielaskdd/fix-file-path-error
fix: Add safe handling for missing file_path in PostgreSQL
2 parents 9d5603d + 9a8f588 commit 364ae23

1 file changed

Lines changed: 18 additions & 2 deletions

File tree

lightrag/kg/postgres_impl.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1976,6 +1976,14 @@ async def get_docs_by_status(
19761976
metadata = json.loads(metadata)
19771977
except json.JSONDecodeError:
19781978
metadata = {}
1979+
# Ensure metadata is a dict
1980+
if not isinstance(metadata, dict):
1981+
metadata = {}
1982+
1983+
# Safe handling for file_path
1984+
file_path = element.get("file_path")
1985+
if file_path is None:
1986+
file_path = "no-file-path"
19791987

19801988
# Convert datetime objects to ISO format strings with timezone info
19811989
created_at = self._format_datetime_with_timezone(element["created_at"])
@@ -1988,7 +1996,7 @@ async def get_docs_by_status(
19881996
created_at=created_at,
19891997
updated_at=updated_at,
19901998
chunks_count=element["chunks_count"],
1991-
file_path=element["file_path"],
1999+
file_path=file_path,
19922000
chunks_list=chunks_list,
19932001
metadata=metadata,
19942002
error_msg=element.get("error_msg"),
@@ -2022,6 +2030,14 @@ async def get_docs_by_track_id(
20222030
metadata = json.loads(metadata)
20232031
except json.JSONDecodeError:
20242032
metadata = {}
2033+
# Ensure metadata is a dict
2034+
if not isinstance(metadata, dict):
2035+
metadata = {}
2036+
2037+
# Safe handling for file_path
2038+
file_path = element.get("file_path")
2039+
if file_path is None:
2040+
file_path = "no-file-path"
20252041

20262042
# Convert datetime objects to ISO format strings with timezone info
20272043
created_at = self._format_datetime_with_timezone(element["created_at"])
@@ -2034,7 +2050,7 @@ async def get_docs_by_track_id(
20342050
created_at=created_at,
20352051
updated_at=updated_at,
20362052
chunks_count=element["chunks_count"],
2037-
file_path=element["file_path"],
2053+
file_path=file_path,
20382054
chunks_list=chunks_list,
20392055
track_id=element.get("track_id"),
20402056
metadata=metadata,

0 commit comments

Comments
 (0)