Skip to content

Commit 7f69ab6

Browse files
committed
Merge remote-tracking branch 'origin/test_zdy_1001' into test_zdy_1001
2 parents 9c8cc61 + 1e09846 commit 7f69ab6

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

src/memos/graph_dbs/polardb.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2140,7 +2140,24 @@ def _parse_node(self, node_data: dict[str, Any]) -> dict[str, Any]:
21402140
if time_field in node and hasattr(node[time_field], "isoformat"):
21412141
node[time_field] = node[time_field].isoformat()
21422142

2143-
# Do not deserialize sources and usage; keep List[str] format
2143+
# Deserialize sources and usage if they are not lists
2144+
for field_name in ["sources", "usage", "tags"]:
2145+
if field_name in node and node[field_name] is not None:
2146+
field_value = node[field_name]
2147+
2148+
# If it's a string, try to parse it as JSON
2149+
if isinstance(field_value, str):
2150+
try:
2151+
node[field_name] = json.loads(field_value)
2152+
except (json.JSONDecodeError, TypeError):
2153+
logger.warning(f"Failed to parse {field_name} as JSON, wrapping in list")
2154+
node[field_name] = [field_value]
2155+
2156+
# If it's not a list, wrap it in a list
2157+
elif not isinstance(field_value, list):
2158+
logger.warning(f"{field_name} is not a list, wrapping value: {type(field_value)}")
2159+
node[field_name] = [field_value]
2160+
21442161
# Do not remove user_name; keep all fields
21452162

21462163
# 1

0 commit comments

Comments
 (0)