Skip empty operands in search query builder (just a test PR)#377
Closed
Skip empty operands in search query builder (just a test PR)#377
Conversation
|
Comment on lines
243
to
+245
| for and_operand in and_operands: | ||
| if not and_operand.strip(): | ||
| # Skip empty or whitespace-only operands |
Contributor
There was a problem hiding this comment.
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.
|
PALVELUKARTTA-API branch is deployed to platta: https://palvelukartta-api-pr377.dev.hel.ninja 🚀🚀🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Refs: PL-210