Harden ingest_event: coerce non-UUID source_id to NULL (tolerates legacy messages)
All checks were successful
build-and-deploy / build (push) Successful in 4m15s

This commit is contained in:
sirius0xdev 2026-07-07 19:44:13 -04:00
parent 67fee36c7c
commit 8c7f17f645
No known key found for this signature in database

View file

@ -4,6 +4,7 @@ from __future__ import annotations
import json import json
import logging import logging
import uuid
from datetime import datetime, timezone from datetime import datetime, timezone
import nats import nats
@ -23,9 +24,19 @@ NATS_DURABLE = "osint-ingestor"
async def ingest_event(msg: dict): async def ingest_event(msg: dict):
"""Ingest a single event from NATS into PostgreSQL.""" """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 = { event_row = {
"source_type": msg.get("source_type", "rss"), "source_type": msg.get("source_type", "rss"),
"source_id": msg.get("source_id"), "source_id": source_id,
"title": msg.get("title"), "title": msg.get("title"),
"body": msg.get("body"), "body": msg.get("body"),
"url": msg.get("url"), "url": msg.get("url"),