diff --git a/backend/pipeline/stages.py b/backend/pipeline/stages.py index 4787658..f466636 100644 --- a/backend/pipeline/stages.py +++ b/backend/pipeline/stages.py @@ -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,