Skip to content

feat(alerts): Include single-written detectors in AlertRuleFetchMixin.fetch_metric_alerts#110673

Merged
kcons merged 3 commits intomasterfrom
kcons/fallbackid
Mar 13, 2026
Merged

feat(alerts): Include single-written detectors in AlertRuleFetchMixin.fetch_metric_alerts#110673
kcons merged 3 commits intomasterfrom
kcons/fallbackid

Conversation

@kcons
Copy link
Copy Markdown
Member

@kcons kcons commented Mar 13, 2026

OrganizationAlertRuleIndexEndpoint and ProjectAlertRuleIndexEndpoint need to be able to include single-written Detectors when organizations:workflow-engine-rule-serializers is enabled.

In addition to single-written support, this removes dependency on AlertRule entirely in that path, ensures we have the appropriate filtering, and sets the count header.
Also, renamed the method to plural to be less confusing, as that confused me previously.

@kcons kcons requested a review from a team as a code owner March 13, 2026 19:26
@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label Mar 13, 2026
Copy link
Copy Markdown
Contributor

@cursor cursor bot left a comment

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 prepared a fix for the issue found in the latest run.

  • ✅ Fixed: Overly broad filter includes issue-rule detectors in metric alerts
    • Changed the filter from Q(alertruledetector__isnull=False) to Q(alertruledetector__alert_rule_id__isnull=False) to only match detectors linked via alert_rule_id (metric alerts), excluding those linked via rule_id (issue rules).

Create PR

Or push these changes by commenting:

@cursor push 4f3dcb3189
Preview (4f3dcb3189)
diff --git a/src/sentry/incidents/endpoints/organization_alert_rule_index.py b/src/sentry/incidents/endpoints/organization_alert_rule_index.py
--- a/src/sentry/incidents/endpoints/organization_alert_rule_index.py
+++ b/src/sentry/incidents/endpoints/organization_alert_rule_index.py
@@ -223,7 +223,7 @@
 
         if use_workflow_engine:
             detectors = Detector.objects.filter(
-                Q(alertruledetector__isnull=False)  # Dual-written
+                Q(alertruledetector__alert_rule_id__isnull=False)  # Dual-written
                 | Q(alertruledetector__isnull=True, type="metric_issue"),  # Single-written
                 project__in=projects,
             )

This Bugbot Autofix run was free. To enable autofix for future PRs, go to the Cursor dashboard.

@kcons kcons merged commit ff765ca into master Mar 13, 2026
57 checks passed
@kcons kcons deleted the kcons/fallbackid branch March 13, 2026 20:43
@github-actions github-actions bot locked and limited conversation to collaborators Mar 29, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Scope: Backend Automatically applied to PRs that change backend components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants