From 1aad1db9f69692c8a206f2964ec9f01ec2d21f72 Mon Sep 17 00:00:00 2001 From: Afonso Coutinho Date: Mon, 20 Jul 2026 08:39:16 +0100 Subject: [PATCH] fix: services research source extraction crashes on a non-dict finding (#1868) --- services/research/research_handler.py | 2 ++ tests/test_svc_research_sources_nondict.py | 15 +++++++++++++++ 2 files changed, 17 insertions(+) create mode 100644 tests/test_svc_research_sources_nondict.py diff --git a/services/research/research_handler.py b/services/research/research_handler.py index 2521f61e1..2ef74a8ef 100644 --- a/services/research/research_handler.py +++ b/services/research/research_handler.py @@ -186,6 +186,8 @@ class ResearchHandler: seen = set() sources = [] for f in findings: + if not isinstance(f, dict): + continue url = f.get("url", "") title = f.get("title", "") or url summary = f.get("summary", "") or f.get("evidence", "") diff --git a/tests/test_svc_research_sources_nondict.py b/tests/test_svc_research_sources_nondict.py new file mode 100644 index 000000000..d7ea63ab2 --- /dev/null +++ b/tests/test_svc_research_sources_nondict.py @@ -0,0 +1,15 @@ +from services.research.research_handler import ResearchHandler + + +def test_extract_sources_skips_non_dict_findings(): + # findings come from the DeepResearcher result list / cached JSON; a + # malformed entry (None or a bare string) made f.get crash and drop every + # real source. + findings = [ + {"url": "https://a.com", "title": "A", "summary": "real analysis of the topic"}, + "junk-row", + None, + {"url": "https://b.com", "summary": "more genuine detail here"}, + ] + out = ResearchHandler._extract_sources(findings) + assert [s["url"] for s in out] == ["https://a.com", "https://b.com"]