Self-hosted AI workspace.
Python
fix: docs RAG query crashes on a non-dict row from the index (#1706)
Afonso Coutinho42cb0d5429d9
diff --git a/services/docs/service.py b/services/docs/service.pyindex b20cf8eae..29a515842 100644--- a/services/docs/service.py+++ b/services/docs/service.py@@ -57,6 +57,7 @@ class DocsService:metadata=r.get("metadata"),)for r in results+ if isinstance(r, dict)]async def index(self, directory: str) -> IndexResult:diff --git a/tests/test_docs_query_nondict_rows.py b/tests/test_docs_query_nondict_rows.pynew file mode 100644index 000000000..91871f14b--- /dev/null+++ b/tests/test_docs_query_nondict_rows.py@@ -0,0 +1,26 @@+import asyncio++from services.docs.service import DocsService+++class _FakeRag:+ """Stands in for RAGManager.search. A corrupt or stale Chroma index can+ return a non-dict row alongside the well-formed ones."""++ def search(self, query, k=5):+ return [+ {"text": "alpha", "source": "a.txt", "score": 0.9},+ "corrupt-row",+ None,+ ]+++def test_query_skips_non_dict_rag_rows():+ # Bypass __init__ (it builds a real RAGManager / Chroma client) and inject+ # a fake search backend.+ svc = DocsService.__new__(DocsService)+ svc.rag = _FakeRag()+ out = asyncio.run(svc.query("anything"))+ # old code called r.get(...) on the str/None rows and raised AttributeError.+ assert [c.text for c in out] == ["alpha"]+ assert out[0].source == "a.txt"