fix: Serialize BodySection Pydantic models to dicts before JSONB storage
Stage 5 parses LLM output into list[BodySection] (Pydantic models) but SQLAlchemy's JSONB column needs plain dicts. Added _serialize_body_sections() helper that calls .model_dump() on each BodySection before DB write. Fixes 'Object of type BodySection is not JSON serializable' errors.
This commit is contained in:
parent
5a71539a2b
commit
6940f172a3
1 changed files with 9 additions and 2 deletions
|
|
@ -936,6 +936,13 @@ def _capture_pipeline_metadata() -> dict:
|
|||
# ── Stage 5: Synthesis ───────────────────────────────────────────────────────
|
||||
|
||||
|
||||
def _serialize_body_sections(sections) -> list | dict | None:
|
||||
"""Convert body_sections to JSON-serializable form for DB storage."""
|
||||
if isinstance(sections, list):
|
||||
return [s.model_dump() if hasattr(s, 'model_dump') else s for s in sections]
|
||||
return sections
|
||||
|
||||
|
||||
def _compute_page_tags(
|
||||
moment_indices: list[int],
|
||||
moment_group: list[tuple],
|
||||
|
|
@ -1513,7 +1520,7 @@ def stage5_synthesis(self, video_id: str, run_id: str | None = None) -> str:
|
|||
# Update existing page
|
||||
existing.title = page_data.title
|
||||
existing.summary = page_data.summary
|
||||
existing.body_sections = page_data.body_sections
|
||||
existing.body_sections = _serialize_body_sections(page_data.body_sections)
|
||||
existing.signal_chains = page_data.signal_chains
|
||||
existing.plugins = page_data.plugins if page_data.plugins else None
|
||||
page_tags = _compute_page_tags(page_moment_indices, moment_group, all_tags)
|
||||
|
|
@ -1528,7 +1535,7 @@ def stage5_synthesis(self, video_id: str, run_id: str | None = None) -> str:
|
|||
topic_category=page_data.topic_category or category,
|
||||
topic_tags=_compute_page_tags(page_moment_indices, moment_group, all_tags),
|
||||
summary=page_data.summary,
|
||||
body_sections=page_data.body_sections,
|
||||
body_sections=_serialize_body_sections(page_data.body_sections),
|
||||
signal_chains=page_data.signal_chains,
|
||||
plugins=page_data.plugins if page_data.plugins else None,
|
||||
source_quality=page_data.source_quality,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue