potpie icon indicating copy to clipboard operation
potpie copied to clipboard

Prevent API Calls with Empty Query Parameter in Search API

Open dhirenmathur opened this issue 8 months ago • 1 comments

Description

Currently, the search API (app/modules/search/search_router.py) allows empty search queries, which leads to unnecessary database operations and API calls. When a user submits a search with an empty query string, the system still processes the request and returns results.

Current Behavior

  • Empty search query strings are accepted
  • The system performs database operations even with empty queries
  • Resources are wasted on meaningless search operations

Expected Behavior

  • Validate the query parameter in SearchRequest
  • Return a 400 Bad Request response when the query is empty or contains only whitespace
  • Include a clear error message explaining that search queries cannot be empty

Code Location

  • app/modules/search/search_router.py
  • app/modules/search/search_schema.py

dhirenmathur avatar Apr 14 '25 14:04 dhirenmathur