fix: skip non-UUID pattern signal IDs in evidence persistence

This commit is contained in:
Celes Renata
2026-04-14 20:18:50 +00:00
parent d37a5732d0
commit e1792e06b9
+15
View File
@@ -11,6 +11,7 @@ from __future__ import annotations
import json
import logging
import time
import uuid as _uuid
from dataclasses import dataclass
from datetime import datetime, timedelta, timezone
from typing import Any
@@ -760,6 +761,15 @@ INSERT INTO trend_evidence (
"""
def _is_valid_uuid(val: str) -> bool:
"""Check if a string is a valid UUID (pattern signal IDs are not)."""
try:
_uuid.UUID(val)
return True
except (ValueError, AttributeError):
return False
async def persist_trend_evidence(
pool: asyncpg.Pool,
trend_window_id: str,
@@ -769,12 +779,17 @@ async def persist_trend_evidence(
"""Insert evidence mapping rows for a trend window. Returns count inserted."""
rows: list[tuple[str, str, str, float, float, float, float, float, float]] = []
for ev in supporting:
# Skip non-UUID document IDs (e.g. pattern signal synthetic IDs)
if not _is_valid_uuid(ev.document_id):
continue
rows.append((
trend_window_id, ev.document_id, "supporting",
ev.rank_score, ev.weight_component, ev.impact_component,
ev.recency_component, ev.confidence_component, ev.sentiment_value,
))
for ev in opposing:
if not _is_valid_uuid(ev.document_id):
continue
rows.append((
trend_window_id, ev.document_id, "opposing",
ev.rank_score, ev.weight_component, ev.impact_component,