Skip to content

fix(search): Return empty result on disjoint group_id intersection#113320

Open
yuvmen wants to merge 1 commit intomasterfrom
yuvmen/fix/group-search-empty-intersection
Open

fix(search): Return empty result on disjoint group_id intersection#113320
yuvmen wants to merge 1 commit intomasterfrom
yuvmen/fix/group-search-empty-intersection

Conversation

@yuvmen
Copy link
Copy Markdown
Member

@yuvmen yuvmen commented Apr 17, 2026

Return an empty search result instead of a 500 whenever the postgres candidate set and the snuba group_id condition are disjoint — any search where the two sides can't both be true at once.

Concretely, SnubaQueryParams._preprocess_group_id_redirects intersects filter_keys["group_id"] (postgres candidates) with the group_id conditions contributed by the search filters. When that intersection is empty the query can't match anything, but today it raises SnubaError("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 snuba group_id = Y condition in format_search_filter, but the postgres-side queryset builder only has a "issue.id" entry in _get_queryset_conditions — not "issue". So a query like is:unresolved issue:<resolved-shortid> leaves postgres returning unresolved candidates (without Y) while snuba still constrains to group_id = Y, and the intersection collapses.

The raise is narrowed to a new EmptyGroupIdIntersectionError subclass so generic except SnubaError handlers keep the existing behavior; only the per-category loop in snuba_search opts 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

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>
@linear-code
Copy link
Copy Markdown

linear-code bot commented Apr 17, 2026

@yuvmen yuvmen marked this pull request as ready for review April 17, 2026 17:27
@yuvmen yuvmen requested review from a team as code owners April 17, 2026 17:27
@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label Apr 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Scope: Backend Automatically applied to PRs that change backend components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant