Skip to content

Commit 7b8fe1a

Browse files
committed
fix(memory): tolerate corrupted metadata json
1 parent 27e4d1d commit 7b8fe1a

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

src/google/adk/memory/sqlite_memory_service.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import hashlib
2020
import inspect
2121
import json
22+
import logging
2223
from pathlib import Path
2324
import sqlite3
2425
import threading
@@ -41,6 +42,8 @@
4142
from ..events.event import Event
4243
from ..sessions.session import Session
4344

45+
logger = logging.getLogger("google_adk." + __name__)
46+
4447

4548
_SCHEMA_VERSION = "1"
4649
_DEFAULT_MAX_RESULTS = 50
@@ -536,9 +539,21 @@ def _row_to_memory_entry(
536539
"updated_at_ms": row["updated_at_ms"],
537540
}
538541
if row["metadata_json"]:
539-
metadata["metadata"] = json.loads(row["metadata_json"])
542+
try:
543+
metadata["metadata"] = json.loads(row["metadata_json"])
544+
except json.JSONDecodeError:
545+
logger.warning(
546+
"Failed to decode metadata_json for session_id %s.",
547+
row["session_id"],
548+
)
540549
if row["extracted_json"]:
541-
metadata["extracted"] = json.loads(row["extracted_json"])
550+
try:
551+
metadata["extracted"] = json.loads(row["extracted_json"])
552+
except json.JSONDecodeError:
553+
logger.warning(
554+
"Failed to decode extracted_json for session_id %s.",
555+
row["session_id"],
556+
)
542557
return MemoryEntry(
543558
id=str(row["id"]),
544559
content=content,

0 commit comments

Comments
 (0)