Skip to content

fix(alerts): Skip issue validation when deleting old subscription during update - #128742

Open
sentry[bot] wants to merge 2 commits into
masterfrom
seer/fix/alerts-skip-issue-validation-on-subscription-update
Open

sentry[bot] wants to merge 2 commits into
masterfrom
seer/fix/alerts-skip-issue-validation-on-subscription-update

Conversation

@sentry

@sentry sentry Bot commented Oct 25, 2026

Copy link
Copy Markdown
Contributor

Problem

When update_subscription_in_snuba runs for an alert rule whose query contains an issue: filter referencing a deleted issue (e.g. issue:ANALYTICS-WERNICKE-SEARCH-1VT), _issue_filter_converter raises InvalidIssueSearchQuery. This crashes the task and blocks the subscription update from completing (~26K errors/day in production).

Fix

Pass skip_field_validation_for_entity_subscription_deletion=True to old_entity_subscription.build_query_builder() in update_subscription_in_snuba, matching the pattern already used by delete_subscription_from_snuba. Added a regression test to UpdateSubscriptionInSnubaTest mirroring the delete test.

Legal Boilerplate

Look, I get it. The entity doing business as "Sentry" was incorporated in the State of Delaware in 2015 as Functional Software, Inc. and is gonna need some rights from me in order to utilize my contributions in this here PR. So here's the deal: I retain all rights, title and interest in and to my contributions, and by keeping this boilerplate intact I confirm that Sentry can use, modify, copy, and redistribute my contributions, under Sentry's choice of terms.

Fixes SENTRY-5SFJ

@sentry <feedback>: Autofix iterates on these changes
@sentry stop iterating: Autofix stops iterating on this run

This PR was automatically generated by Sentry. You can adjust this setting at any time.

@sentry
sentry Bot requested a review from a team as a code owner October 25, 2026 10:47
@github-actions github-actions Bot added the Scope: Backend Automatically applied to PRs that change backend components label Oct 25, 2026

@cursor cursor Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit a7ababb. Configure here.

sub = QuerySubscription.objects.get(id=sub.id)
assert sub.status == QuerySubscription.Status.ACTIVE.value
assert sub.subscription_id is not None
assert sub.subscription_id != subscription_id

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Update test fails on create

Medium Severity

The new test uses issue:INVALID-1 as the current query and does not pass old_query. After the skip-validation delete, _create_in_snuba rebuilds that query without skip_field_validation_for_entity_subscription_deletion, so _issue_filter_converter raises and the task fails with SubscriptionError instead of becoming ACTIVE.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit a7ababb. Configure here.

@github-actions

Copy link
Copy Markdown
Contributor

Backend Test Failures

Failures on 94608e1 in this run:

tests/sentry/snuba/test_tasks.py::UpdateSubscriptionInSnubaTest::test_invalid_subscription_query — log
[gw1] linux -- Python 3.13.17 /home/runner/work/sentry/sentry/.venv/bin/python3
src/sentry/search/events/datasets/discover.py:1726: in _issue_filter_converter
    groups = Group.objects.by_qualified_short_id_bulk(
src/sentry/models/group.py:636: in by_qualified_short_id_bulk
    raise Group.DoesNotExist()
E   sentry.models.group.Group.DoesNotExist

During handling of the above exception, another exception occurred:
src/sentry/snuba/tasks.py:259: in _create_in_snuba
    snql_query = entity_subscription.build_query_builder(
src/sentry/snuba/entity_subscription.py:231: in build_query_builder
    return query_builder_cls(
src/sentry/search/events/builder/errors.py:38: in __init__
    super().__init__(*args, **kwargs)
src/sentry/search/events/builder/base.py:282: in __init__
    self.resolve_query(
src/sentry/search/events/builder/errors.py:82: in resolve_query
    super().resolve_query(query, selected_columns, groupby_columns, equations, orderby)
src/sentry/search/events/builder/base.py:343: in resolve_query
    self.where, self.having = self.resolve_conditions(query)
                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
src/sentry/search/events/builder/base.py:450: in resolve_conditions
    where, having = self.resolve_boolean_conditions(parsed_terms)
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
src/sentry/search/events/builder/base.py:514: in resolve_boolean_conditions
    rhs_where, rhs_having = self.resolve_boolean_conditions(rhs)
                            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
src/sentry/search/events/builder/base.py:466: in resolve_boolean_conditions
    return self.resolve_boolean_condition(terms[0])
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
src/sentry/search/events/builder/base.py:551: in resolve_boolean_condition
    return self.resolve_boolean_conditions(term.children)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
src/sentry/search/events/builder/base.py:466: in resolve_boolean_conditions
    return self.resolve_boolean_condition(terms[0])
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
src/sentry/search/events/builder/base.py:556: in resolve_boolean_condition
    where = self.resolve_where([term])
            ^^^^^^^^^^^^^^^^^^^^^^^^^^
src/sentry/search/events/builder/base.py:402: in resolve_where
    condition = self.format_search_filter(term)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
src/sentry/search/events/builder/discover.py:141: in format_search_filter
    converted_filter = self.convert_search_filter_to_condition(
src/sentry/search/events/builder/base.py:1219: in convert_search_filter_to_condition
    return converter(search_filter)
           ^^^^^^^^^^^^^^^^^^^^^^^^
src/sentry/search/events/datasets/discover.py:1733: in _issue_filter_converter
    raise InvalidIssueSearchQuery(group_short_ids)
E   sentry.search.exceptions.InvalidIssueSearchQuery: Issue IDs do not exist: ['INVALID-1']
... (13 more lines)

This branch has not been deployed

No deployments
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.

0 participants