Skip to content

Self-hosted AI workspace.

Python

fix: search service crashes on a non-dict result row (#1725)

Afonso Coutinhof4c1dad3c21a
diff --git a/services/search/service.py b/services/search/service.py
index dcb662dfa..dab6ab6f4 100644
--- a/services/search/service.py
+++ b/services/search/service.py
@@ -73,6 +73,8 @@ class SearchService:
results = []
for r in raw_results:
+ if not isinstance(r, dict):
+ continue
results.append(SearchResult(
url=r.get("url", ""),
title=r.get("title", ""),
diff --git a/tests/test_search_service_nondict_rows.py b/tests/test_search_service_nondict_rows.py
new file mode 100644
index 000000000..1e1b1797e
--- /dev/null
+++ b/tests/test_search_service_nondict_rows.py
@@ -0,0 +1,23 @@
+import asyncio
+
+import services.search.service as svc_mod
+from services.search.service import SearchService
+
+
+def test_search_skips_non_dict_results(monkeypatch):
+ # comprehensive_web_search aggregates external provider + cache results;
+ # a malformed row (string/None) made the old loop call r.get and crash,
+ # losing the whole search.
+ async def fake_search(query, max_results=10, fetch_content=False):
+ return [
+ {"url": "https://a.com", "title": "A", "snippet": "x"},
+ "junk-row",
+ None,
+ {"url": "https://b.com", "title": "B", "snippet": "y"},
+ ]
+
+ monkeypatch.setattr(svc_mod, "comprehensive_web_search", fake_search)
+ svc = SearchService()
+ res = asyncio.run(svc.search("anything"))
+ assert [r.url for r in res.results] == ["https://a.com", "https://b.com"]
+ assert res.total == 2