From 71042212c8cbebb79240894db5fed3b20e8179d9 Mon Sep 17 00:00:00 2001 From: fch-aa <21101725+fch-aa@users.noreply.github.com> Date: Sun, 16 Aug 2026 19:01:07 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B(backend)=20fix=20scoped=20full-tex?= =?UTF-8?q?t=20search?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Document-scoped indexer searches attempted to call a queryset method on a Document instance and failed before reaching Find. Resolve the path from the queryset and cover the scoped request. Signed-off-by: fch-aa <21101725+fch-aa@users.noreply.github.com> --- CHANGELOG.md | 1 + src/backend/core/api/viewsets.py | 4 ++-- .../documents/test_api_documents_search.py | 17 +++++++++++++++++ 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 53dd6ff375..8246a57327 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,7 @@ and this project adheres to ### Fixed +- 🐛(backend) fix full-text search scoped to a document - 🐛(frontend) refresh pins after document deletion and restoration - 🐛(frontend) redirect homepage to login when homepage feat is disabled #2521 - 🐛(backend) ignore CSPs for API docs in development diff --git a/src/backend/core/api/viewsets.py b/src/backend/core/api/viewsets.py index e63fb726de..076db9b28f 100644 --- a/src/backend/core/api/viewsets.py +++ b/src/backend/core/api/viewsets.py @@ -1550,8 +1550,8 @@ def _search_using_indexer(indexer, request, params, search_type): document_id = params.validated_data.get("document") if document_id: try: - path = models.Document.objects.get(pk=document_id).values_list( - "path", flat=True + path = models.Document.objects.values_list("path", flat=True).get( + pk=document_id ) except models.Document.DoesNotExist as exc: raise drf.exceptions.NotFound("Document not found.") from exc diff --git a/src/backend/core/tests/documents/test_api_documents_search.py b/src/backend/core/tests/documents/test_api_documents_search.py index 4ccc1f00ba..5e4b515c1c 100644 --- a/src/backend/core/tests/documents/test_api_documents_search.py +++ b/src/backend/core/tests/documents/test_api_documents_search.py @@ -612,3 +612,20 @@ def test_api_documents_search_success(indexer_settings): assert results == [ {"id": document["id"], "title": document["title"], "path": document["path"]} ] + + +@mock.patch("core.services.search_indexers.FindDocumentIndexer.search_query") +def test_api_documents_search_success_scoped(search_query, indexer_settings): + """A document-scoped indexer search should use the document path.""" + indexer_settings.SEARCH_URL = "http://find/api/v1.0/search" + search_query.return_value = [] + document = factories.DocumentFactory() + + response = APIClient().get( + "/api/v1.0/documents/search/", + data={"q": "alpha", "document": document.id}, + ) + + assert response.status_code == 200 + assert search_query.call_count == 1 + assert search_query.call_args.kwargs["data"]["path"] == document.path