Skip to content

Comments

Skip empty operands in search query builder (just a test PR)#377

Closed
tuomas777 wants to merge 1 commit intomainfrom
PL-210-search-empty-operands-take-2
Closed

Skip empty operands in search query builder (just a test PR)#377
tuomas777 wants to merge 1 commit intomainfrom
PL-210-search-empty-operands-take-2

Conversation

@tuomas777
Copy link
Contributor

Refs: PL-210

@tuomas777 tuomas777 requested a review from a team as a code owner January 29, 2026 12:39
@sonarqubecloud
Copy link

Comment on lines 243 to +245
for and_operand in and_operands:
if not and_operand.strip():
# Skip empty or whitespace-only operands
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: A search query with only operators (e.g., " | ") causes build_search_query to return an empty string, leading to a database error and a 400 response.
Severity: MEDIUM

Suggested Fix

After calling build_search_query, add a check to verify if the returned search_query_str is empty. If it is, bypass the database query and return an empty result set directly to prevent the to_tsquery syntax error.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.

Location: services/search/api.py#L243-L245

Potential issue: A search query containing only operators and whitespace, such as `"  |
"` or `"  &  "`, passes the initial validation. However, the `build_search_query`
function will process this input and return an empty string. This empty string is then
passed to PostgreSQL's `to_tsquery` function within the search SQL statement, which
causes a database syntax error. The application catches this error and returns an HTTP
400 Bad Request to the user, instead of the expected behavior of returning zero search
results.

Did we get this right? 👍 / 👎 to inform future reviews.

@azure-pipelines
Copy link

PALVELUKARTTA-API branch is deployed to platta: https://palvelukartta-api-pr377.dev.hel.ninja 🚀🚀🚀

@tuomas777 tuomas777 closed this Feb 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant