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
All checks were successful
build-and-deploy / build (push) Successful in 4m15s
This commit is contained in:
parent
67fee36c7c
commit
8c7f17f645
1 changed files with 12 additions and 1 deletions
|
|
@ -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"),
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue