From 8c7f17f6454a7a2be3186e060043d5e0cf3f2ec1 Mon Sep 17 00:00:00 2001 From: sirius0xdev Date: Tue, 7 Jul 2026 19:44:13 -0400 Subject: [PATCH] Harden ingest_event: coerce non-UUID source_id to NULL (tolerates legacy messages) --- app/ingestor.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/app/ingestor.py b/app/ingestor.py index 29eae1c..6000aab 100644 --- a/app/ingestor.py +++ b/app/ingestor.py @@ -4,6 +4,7 @@ from __future__ import annotations import json import logging +import uuid from datetime import datetime, timezone import nats @@ -23,9 +24,19 @@ NATS_DURABLE = "osint-ingestor" async def ingest_event(msg: dict): """Ingest a single event from NATS into PostgreSQL.""" + # source_id links to a feed_sources UUID; tolerate non-UUID / missing values + # (e.g. legacy messages that carried a URL) by coercing to None. + raw_source_id = msg.get("source_id") + source_id = None + if raw_source_id is not None: + try: + source_id = str(uuid.UUID(str(raw_source_id))) + except (ValueError, AttributeError, TypeError): + source_id = None + event_row = { "source_type": msg.get("source_type", "rss"), - "source_id": msg.get("source_id"), + "source_id": source_id, "title": msg.get("title"), "body": msg.get("body"), "url": msg.get("url"),