From 55388e7088b1e9ca5190817fcc5832e507e9416a Mon Sep 17 00:00:00 2001 From: Vishnu Kosuri Date: Sat, 14 Mar 2026 13:48:11 +0530 Subject: [PATCH] fix: return 400 when text_search is called without a text parameter Calling /rest/v1/text_search without the text query parameter passed None to db.text_search(), which then called re.search() with None and raised a TypeError, resulting in a 500 instead of a descriptive 400. Added a guard in the endpoint and a regression test covering both the missing-parameter and empty-string cases. Co-Authored-By: Claude Sonnet 4.6 --- application/tests/web_main_test.py | 8 ++++++++ application/web/web_main.py | 2 ++ 2 files changed, 10 insertions(+) diff --git a/application/tests/web_main_test.py b/application/tests/web_main_test.py index 9e219b4ce..322d47515 100644 --- a/application/tests/web_main_test.py +++ b/application/tests/web_main_test.py @@ -475,6 +475,14 @@ def test_test_search(self) -> None: self.assertEqual(200, resp.status_code) self.assertDictEqual(resp.json[0], expected[0]) + def test_text_search_missing_param(self) -> None: + with self.app.test_client() as client: + response = client.get("/rest/v1/text_search") + self.assertEqual(400, response.status_code) + + response = client.get("/rest/v1/text_search?text=") + self.assertEqual(400, response.status_code) + def test_find_root_cres(self) -> None: self.maxDiff = None collection = db.Node_collection().with_graph() diff --git a/application/web/web_main.py b/application/web/web_main.py index 29567470a..3e76fab9c 100644 --- a/application/web/web_main.py +++ b/application/web/web_main.py @@ -472,6 +472,8 @@ def text_search() -> Any: """ database = db.Node_collection() text = request.args.get("text") + if not text: + abort(400, "text parameter is required") if posthog: posthog.capture(f"text_search", f"text:{text}")