Fix JSONB fields returned as strings from database
Parse JSONB fields (provenance, origin, tags, metadata, object_data, signature) if they come back as strings instead of dicts. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
14
db.py
14
db.py
@@ -317,6 +317,13 @@ def _parse_asset_row(row) -> dict:
|
||||
asset["created_at"] = asset["created_at"].isoformat()
|
||||
if asset.get("updated_at"):
|
||||
asset["updated_at"] = asset["updated_at"].isoformat()
|
||||
# Ensure JSONB fields are dicts (handle string case)
|
||||
for field in ("tags", "metadata", "provenance", "origin"):
|
||||
if isinstance(asset.get(field), str):
|
||||
try:
|
||||
asset[field] = json.loads(asset[field])
|
||||
except (json.JSONDecodeError, TypeError):
|
||||
pass
|
||||
return asset
|
||||
|
||||
|
||||
@@ -413,6 +420,13 @@ def _parse_activity_row(row) -> dict:
|
||||
# Convert datetime to ISO string
|
||||
if activity.get("published"):
|
||||
activity["published"] = activity["published"].isoformat()
|
||||
# Ensure JSONB fields are dicts (handle string case)
|
||||
for field in ("object_data", "signature"):
|
||||
if isinstance(activity.get(field), str):
|
||||
try:
|
||||
activity[field] = json.loads(activity[field])
|
||||
except (json.JSONDecodeError, TypeError):
|
||||
pass
|
||||
return activity
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user