From 11e5ca6e679e2c696e437fa6a21d6cef77e0da4b Mon Sep 17 00:00:00 2001 From: Shiwani Mishra Date: Sat, 4 Apr 2026 19:48:24 +0530 Subject: [PATCH] fix: return 400 when text param is missing in text_search Closes #862 request.args.get('text') returns None if the query param is absent. Passing None into db.text_search() causes re.search() to raise TypeError: expected string or bytes-like object. Return a 400 before reaching the database call. --- application/tests/web_main_test.py | 6 ++++++ application/web/web_main.py | 2 ++ 2 files changed, 8 insertions(+) diff --git a/application/tests/web_main_test.py b/application/tests/web_main_test.py index 9e219b4ce..90bb3a999 100644 --- a/application/tests/web_main_test.py +++ b/application/tests/web_main_test.py @@ -450,6 +450,12 @@ def test_test_search(self) -> None: collection.add_node(docs["sa"]) 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) + response = client.get(f"/rest/v1/text_search?text='CRE:2'") self.assertEqual(404, response.status_code) diff --git a/application/web/web_main.py b/application/web/web_main.py index 29567470a..c138334ac 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: + return jsonify({"error": "text parameter is required"}), 400 if posthog: posthog.capture(f"text_search", f"text:{text}")