From 7d6bac7b0e88b17cf8290c91359dafbb1363b7eb Mon Sep 17 00:00:00 2001 From: Matt Van Horn Date: Sun, 15 Feb 2026 07:29:27 -0800 Subject: [PATCH] fix: handle engagement: null in watchlist and YouTube normalizer When X posts return engagement: null, dict.get("engagement", {}) returns None (key exists with null value), causing AttributeError. Use `or {}` idiom to coalesce None to empty dict. Co-Authored-By: Claude Opus 4.6 --- scripts/lib/normalize.py | 2 +- scripts/watchlist.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/lib/normalize.py b/scripts/lib/normalize.py index 941a9bf..3fd61a9 100644 --- a/scripts/lib/normalize.py +++ b/scripts/lib/normalize.py @@ -174,7 +174,7 @@ def normalize_youtube_items( for item in items: # Parse engagement - eng_raw = item.get("engagement", {}) + eng_raw = item.get("engagement") or {} engagement = schema.Engagement( views=eng_raw.get("views"), likes=eng_raw.get("likes"), diff --git a/scripts/watchlist.py b/scripts/watchlist.py index a058d25..4ec424f 100644 --- a/scripts/watchlist.py +++ b/scripts/watchlist.py @@ -185,7 +185,7 @@ def _run_topic(topic: dict) -> dict: "title": item.get("text", "")[:100], "author": item.get("author_handle", ""), "content": item.get("text", ""), - "engagement_score": item.get("engagement", {}).get("likes", 0), + "engagement_score": (item.get("engagement") or {}).get("likes", 0), "relevance_score": item.get("relevance", 0), })