AI agent skill that researches any topic across Reddit, X, YouTube, HN, Polymarket, and the web - then synthesizes a grounded summary
Python ai-promptsai-skillblueskyclaudeclaude-codeclawhubdeep-researchhackernewsinstagramopenclawpolymarketrecencyredditresearchsocial-mediatiktoktrendstwitterweb-searchyoutube
fix(store): guard new_engagement against None in store_findings update path
Nicole Finateric0e9fbf80be7
diff --git a/changelog.d/796.fixed.md b/changelog.d/796.fixed.mdnew file mode 100644index 00000000..6e8881a0--- /dev/null+++ b/changelog.d/796.fixed.md@@ -0,0 +1 @@+`store_findings` no longer raises `TypeError` when a re-sighted finding carries `engagement_score: None`.diff --git a/skills/last30days/scripts/store.py b/skills/last30days/scripts/store.pyindex 5b7efa3f..55faccc8 100644--- a/skills/last30days/scripts/store.py+++ b/skills/last30days/scripts/store.py@@ -484,7 +484,7 @@ def store_findings(for url, f in with_urls:existing = existing_by_url.get(url)- new_engagement = f.get("engagement_score", 0)+ new_engagement = f.get("engagement_score") or 0if existing:update_rows.append((max(new_engagement, existing["engagement_score"] or 0),diff --git a/tests/test_store.py b/tests/test_store.pyindex 61bffeff..777c9b0b 100644--- a/tests/test_store.py+++ b/tests/test_store.py@@ -1204,6 +1204,48 @@ def test_list_discovery_queue_orders_by_last_surfaced_and_filters_status(temp_dbassert [r["name"] for r in covered] == ["Covered topic"]+def test_store_findings_none_engagement_on_update_does_not_crash(temp_db):+ """Regression: store_findings must not TypeError when an update-path finding+ carries engagement_score=None.++ .get("engagement_score", 0) only substitutes 0 for an *absent* key, so a+ present-but-None value reached max(None, existing) on the update branch.+ store_findings accepts arbitrary List[Dict[str, Any]] callers, so the+ boundary must stay null-safe (engagement_score is float | None in schema.py).+ """+ topic_id = store.add_topic("None Engagement Topic")["id"]+ url = "https://example.com/none-engagement"+ base = {+ "source": "reddit",+ "source_url": url,+ "source_title": "T",+ "author": "",+ "content": "",+ "summary": "",+ "relevance_score": 0.5,+ }++ # First sighting carries a real engagement score.+ run1 = store.record_run(topic_id, source_mode="test", status="running")+ store.store_findings(run1, topic_id, [{**base, "engagement_score": 5.0}])++ # Re-sighting the same URL with engagement_score=None takes the UPDATE branch;+ # before the fix this raised TypeError from max(None, 5.0).+ run2 = store.record_run(topic_id, source_mode="test", status="running")+ counts = store.store_findings(run2, topic_id, [{**base, "engagement_score": None}])+ assert counts["updated"] == 1++ con = sqlite3.connect(str(temp_db))+ try:+ stored = con.execute(+ "SELECT engagement_score FROM findings WHERE source_url = ?", (url,)+ ).fetchone()[0]+ finally:+ con.close()+ # max(None -> 0, existing 5.0) keeps the higher real score.+ assert stored == 5.0++if __name__ == "__main__":pytest.main([__file__, "-v"])