fix(search): Return empty result on disjoint group_id intersection#113320
Open
fix(search): Return empty result on disjoint group_id intersection#113320
Conversation
When a query's postgres candidate set and the snuba-side group_id condition have no overlap (e.g. `is:unresolved issue:<resolved-shortid>`, where the `issue:` alias is not applied to the postgres queryset), `SnubaQueryParams._preprocess_group_id_redirects` raises SnubaError, which surfaces as a 500. Catch this in the per-category loop of `snuba_search` and skip the category so the search returns zero results, matching the user's intent. The raise is narrowed to a new `EmptyGroupIdIntersectionError` subclass so generic `except SnubaError` handlers still catch it and only opt-in callers treat it as empty. Fixes SENTRY-5MNH Co-Authored-By: Claude <noreply@anthropic.com>
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.
Return an empty search result instead of a 500 whenever the postgres candidate set and the snuba
group_idcondition are disjoint — any search where the two sides can't both be true at once.Concretely,
SnubaQueryParams._preprocess_group_id_redirectsintersectsfilter_keys["group_id"](postgres candidates) with thegroup_idconditions contributed by the search filters. When that intersection is empty the query can't match anything, but today it raisesSnubaError("Found empty intersection of group_ids")and surfaces as an internal error.One example that hits this in production (SENTRY-5MNH):
issue:<shortid>gets rewritten into a snubagroup_id = Ycondition informat_search_filter, but the postgres-side queryset builder only has a"issue.id"entry in_get_queryset_conditions— not"issue". So a query likeis:unresolved issue:<resolved-shortid>leaves postgres returning unresolved candidates (without Y) while snuba still constrains togroup_id = Y, and the intersection collapses.The raise is narrowed to a new
EmptyGroupIdIntersectionErrorsubclass so genericexcept SnubaErrorhandlers keep the existing behavior; only the per-category loop insnuba_searchopts in to treat it as zero results. If all categories skip,bulk_raw_query([])naturally yields an empty result.Fixes SENTRY-5MNH
Refs ID-1482