feat(alerts): Include single-written detectors in AlertRuleFetchMixin.fetch_metric_alerts#110673
Merged
feat(alerts): Include single-written detectors in AlertRuleFetchMixin.fetch_metric_alerts#110673
Conversation
….fetch_metric_alerts
Contributor
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
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).
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.
src/sentry/incidents/endpoints/organization_alert_rule_index.py
Outdated
Show resolved
Hide resolved
ceorourke
approved these changes
Mar 13, 2026
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.


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.