fix: coerce non-string metadata values to strings in MemoryFact.parse_metadata#2623
fix: coerce non-string metadata values to strings in MemoryFact.parse_metadata#2623handnewb wants to merge 2 commits into
Conversation
…_metadata
When memory_units contain metadata with non-string values (e.g.,
{"original_id": 348} from observation bookmarks), the consolidation
worker fails with:
ValidationError: metadata.original_id — Input should be a valid string
This happens because metadata is typed as dict[str, str] but JSONB
columns can store integers. The parse_metadata validator handles
str→dict coercion (asyncpg) but not int→str coercion for values.
Fix: coerce all dict values to strings after JSON parsing.
Fixes consolidation blocking on banks with numeric original_id values.
|
verified this fixes #2622 — reproduced the one follow-up (not for this PR): the same |
Summary
Fix consolidation blocker caused by non-string metadata values in MemoryFact.
Problem
When
memory_unitscontain metadata with non-string values (e.g.,{"original_id": 348}from observation bookmarks), the consolidation worker fails with:This happens because
MemoryFact.metadatais typed asdict[str, str]but theparse_metadatavalidator doesn't coerce non-string dict values.Root Cause
In
engine/response_models.py:253,metadata: dict[str, str]. The@field_validator("metadata")method only handlesstr → dictcoercion (for asyncpg JSONB serialization), notint/other → strcoercion for individual values.Fix
Added value coercion in
parse_metadata: after JSON parsing (or on raw dict input), iterate all key-value pairs and convert both to strings with{str(k): str(val) for k, val in v.items()}. This safely handles integer, float, bool, and None values.Impact
Testing
Closes #2622