fix: research source extraction crashes on a non-dict finding (#1714)

This commit is contained in:
Afonso Coutinho
2026-06-03 05:34:40 +01:00
committed by GitHub
parent 29e19f326a
commit f6f86c4b34
2 changed files with 17 additions and 0 deletions

View File

@@ -461,6 +461,8 @@ class ResearchHandler:
seen = set() seen = set()
sources = [] sources = []
for f in findings: for f in findings:
if not isinstance(f, dict):
continue
url = f.get("url", "") url = f.get("url", "")
title = f.get("title", "") or url title = f.get("title", "") or url
summary = f.get("summary", "") or f.get("evidence", "") summary = f.get("summary", "") or f.get("evidence", "")

View File

@@ -0,0 +1,15 @@
from src.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 the old loop call .get on a
# non-dict and crash, dropping every real source in the set.
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"]