mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2026-08-19 17:23:21 +00:00
feat(api): surface every search query error, not just the first
When parse_user_query() raises MultipleSearchQueryErrors due to multiple field parsing failures (e.g. both an invalid date and an invalid number in a single query), the exception handler now surfaces all error messages in the 400 response, allowing users to fix them all in one round-trip instead of discovering them one at a time. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 5
parent
0353b04f4b
commit
bb157726c9
@@ -801,6 +801,26 @@ class TestDocumentSearchApi(DirectoriesMixin, APITestCase):
|
||||
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
|
||||
self.assertIn("invalid-date", str(response.data["query"]))
|
||||
|
||||
def test_search_multiple_bad_fields_returns_all_messages(self) -> None:
|
||||
"""
|
||||
GIVEN:
|
||||
- One document added
|
||||
WHEN:
|
||||
- Query with multiple bad fields (e.g. invalid date and invalid number)
|
||||
THEN:
|
||||
- 400 Bad Request with error messages for every bad field,
|
||||
so the user can fix them all in one round-trip
|
||||
"""
|
||||
response = self.client.get(
|
||||
"/api/documents/",
|
||||
{"query": "created:notadate AND asn:notanumber"},
|
||||
)
|
||||
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
|
||||
messages = response.data["query"]
|
||||
self.assertEqual(len(messages), 2)
|
||||
self.assertTrue(any("created" in m for m in messages))
|
||||
self.assertTrue(any("asn" in m for m in messages))
|
||||
|
||||
@override_settings(
|
||||
TIME_ZONE="UTC",
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user