From a21c66eaa87cf27acba2c12f8d370503c8b76575 Mon Sep 17 00:00:00 2001 From: "claude[bot]" <209825114+claude[bot]@users.noreply.github.com> Date: Mon, 23 Jun 2025 04:30:15 +0000 Subject: [PATCH 1/2] fix: handle None from_entity in Context API RelationSummary Add null check before accessing from_entity.title to prevent AttributeError when relations exist but referenced entities are deleted or inconsistent. Follows the same pattern already used for to_entity handling. Fixes #165 Co-authored-by: Drew Cain --- src/basic_memory/api/routers/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/basic_memory/api/routers/utils.py b/src/basic_memory/api/routers/utils.py index 82aa173b4..f7ce922a1 100644 --- a/src/basic_memory/api/routers/utils.py +++ b/src/basic_memory/api/routers/utils.py @@ -52,7 +52,7 @@ async def to_summary(item: SearchIndexRow | ContextResultRow): file_path=item.file_path, permalink=item.permalink, # pyright: ignore relation_type=item.relation_type, # pyright: ignore - from_entity=from_entity.title, # pyright: ignore + from_entity=from_entity.title if from_entity else None, to_entity=to_entity.title if to_entity else None, created_at=item.created_at, ) From b566692627505a88c7117f48956d6c61701952bc Mon Sep 17 00:00:00 2001 From: Drew Cain Date: Sun, 22 Jun 2025 23:50:18 -0500 Subject: [PATCH 2/2] fix: handle None from_entity in Context API RelationSummary Update typedef for RelationSummary Signed-off-by: Drew Cain --- src/basic_memory/schemas/memory.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/basic_memory/schemas/memory.py b/src/basic_memory/schemas/memory.py index b16a7c750..34e51df1a 100644 --- a/src/basic_memory/schemas/memory.py +++ b/src/basic_memory/schemas/memory.py @@ -134,7 +134,7 @@ class RelationSummary(BaseModel): file_path: str permalink: str relation_type: str - from_entity: str + from_entity: Optional[str] = None to_entity: Optional[str] = None created_at: datetime