fix: rename Note.metadata → entity_meta (reserved by SQLAlchemy Declarative API)

SQLAlchemy reserves 'metadata' as a class attribute on declarative models.
Renamed to 'entity_meta' with explicit column name 'metadata' so the DB
column is unchanged but the Python attribute no longer conflicts.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-31 18:13:47 -04:00
parent 80f30b705d
commit 95056d5be7
4 changed files with 11 additions and 10 deletions
+3 -2
View File
@@ -54,7 +54,8 @@ class Note(Base, TimestampMixin):
# Entity type — 'note' (default), 'person', 'place', 'list'
note_type: Mapped[str] = mapped_column(Text, default="note", server_default="note")
# Structured metadata for entity types (person/place/list)
metadata: Mapped[dict | None] = mapped_column(JSONB, nullable=True)
# Named 'entity_meta' to avoid collision with SQLAlchemy's reserved 'metadata' attribute
entity_meta: Mapped[dict | None] = mapped_column("metadata", JSONB, nullable=True)
__table_args__ = (
Index("ix_notes_tags", "tags", postgresql_using="gin"),
@@ -97,7 +98,7 @@ class Note(Base, TimestampMixin):
),
"is_task": self.is_task,
"note_type": self.entity_type,
"metadata": self.metadata or {},
"metadata": self.entity_meta or {},
"created_at": self.created_at.isoformat(),
"updated_at": self.updated_at.isoformat(),
}
+3 -3
View File
@@ -12,7 +12,7 @@ _SNIPPET_LEN = 200
def _note_to_item(note: Note) -> dict:
meta = note.metadata or {}
meta = note.entity_meta or {}
item: dict = {
"id": note.id,
"note_type": note.entity_type,
@@ -184,14 +184,14 @@ async def get_people_and_places_context(user_id: int) -> str:
if people:
parts = []
for p in people:
meta = p.metadata or {}
meta = p.entity_meta or {}
rel = meta.get("relationship", "")
parts.append(f"{p.title}" + (f" ({rel})" if rel else ""))
lines.append("Known people: " + ", ".join(parts))
if places:
parts = []
for p in places:
meta = p.metadata or {}
meta = p.entity_meta or {}
addr = meta.get("address", "")
parts.append(f"{p.title}" + (f" {addr}" if addr else ""))
lines.append("Known places: " + "; ".join(parts))
+2 -2
View File
@@ -58,7 +58,7 @@ async def create_note(
due_date: date | None = None,
recurrence_rule: dict | None = None,
note_type: str = "note",
metadata: dict | None = None,
entity_meta: dict | None = None,
) -> Note:
# Auto-populate project_id from milestone when not explicitly provided
if milestone_id is not None and project_id is None:
@@ -85,7 +85,7 @@ async def create_note(
due_date=due_date,
recurrence_rule=recurrence_rule,
note_type=note_type,
metadata=metadata,
entity_meta=entity_meta,
)
session.add(note)
await session.commit()
+3 -3
View File
@@ -2043,7 +2043,7 @@ async def execute_tool(
body="\n".join(body_lines),
tags=["person"],
note_type="person",
metadata=meta,
entity_meta=meta,
)
_schedule_embedding(note.id, user_id, name, note.body)
return {"success": True, "type": "person", "data": {"id": note.id, "name": name}}
@@ -2075,7 +2075,7 @@ async def execute_tool(
body="\n".join(body_lines),
tags=["place"],
note_type="place",
metadata=meta,
entity_meta=meta,
)
_schedule_embedding(note.id, user_id, name, note.body)
return {"success": True, "type": "place", "data": {"id": note.id, "name": name}}
@@ -2101,7 +2101,7 @@ async def execute_tool(
body=body,
tags=tags,
note_type="list",
metadata=meta,
entity_meta=meta,
)
_schedule_embedding(note.id, user_id, name, body)
return {"success": True, "type": "list", "data": {"id": note.id, "name": name, "item_count": len(items)}}