Skip to content

Commit 1f6757d

Browse files
lijicodefridayL
andauthored
feat: fix sources (#404)
* feat: fix sources * feat: fix sources --------- Co-authored-by: chunyu li <78344051+fridayL@users.noreply.github.com>
1 parent 5ff29d1 commit 1f6757d

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

src/memos/memories/textual/item.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""Defines memory item types for textual memory."""
22

33
import json
4+
import logging
45
import uuid
56

67
from datetime import datetime
@@ -123,6 +124,25 @@ class TreeNodeTextualMemoryMetadata(TextualMemoryMetadata):
123124
def coerce_sources(cls, v):
124125
if v is None:
125126
return v
127+
# Handle string representation of sources (e.g., from PostgreSQL array or malformed data)
128+
if isinstance(v, str):
129+
logging.info(f"[coerce_sources] v: {v} type: {type(v)}")
130+
# If it's a string that looks like a list representation, try to parse it
131+
# This handles cases like: "[uuid1, uuid2, uuid3]" or "[item1, item2]"
132+
v_stripped = v.strip()
133+
if v_stripped.startswith("[") and v_stripped.endswith("]"):
134+
# Remove brackets and split by comma
135+
content = v_stripped[1:-1].strip()
136+
if content:
137+
# Split by comma and clean up each item
138+
items = [item.strip() for item in content.split(",")]
139+
# Convert to list of strings
140+
v = items
141+
else:
142+
v = []
143+
else:
144+
# Single string, wrap in list
145+
v = [v]
126146
if not isinstance(v, list):
127147
raise TypeError("sources must be a list")
128148
out = []

0 commit comments

Comments
 (0)