Skip to content

Conversation

@ameliahsu
Copy link
Member

When looking up a Detector via alert rule id, it's possible that there is no corresponding row in the AlertRuleDetector table. We then assume that the alert rule id that was passed is a fake id, so we can use get_object_id_from_fake_id() to get the detector.

@ameliahsu ameliahsu requested a review from mifu67 November 25, 2025 22:58
@ameliahsu ameliahsu requested a review from a team as a code owner November 25, 2025 22:58
@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label Nov 25, 2025
Copy link
Contributor

@mifu67 mifu67 left a comment

Choose a reason for hiding this comment

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

"alertRuleId": str(alert_rule_id),
"ruleId": None,
}
)
Copy link
Contributor

Choose a reason for hiding this comment

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

Bug: Fallback ignores detector_id and rule_id filters

The fallback logic activates whenever alert_rule_id is provided, even when combined with detector_id or rule_id filters. It then returns a detector based solely on the calculated detector ID from alert_rule_id, completely ignoring the other filter parameters. This creates inconsistent results where a user requests specific detector_id or rule_id values but receives data for a different detector derived from the alert_rule_id. The fallback should either validate that filters are consistent or only activate when alert_rule_id is the sole filter.

Fix in Cursor Fix in Web

Comment on lines 82 to 91
calculated_detector_id = get_object_id_from_fake_id(int(alert_rule_id))
detector = Detector.objects.get(id=calculated_detector_id)

if detector:
return Response(
{
"detectorId": str(detector.id),
"alertRuleId": str(alert_rule_id),
"ruleId": None,
}

This comment was marked as outdated.

@codecov
Copy link

codecov bot commented Nov 25, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@             Coverage Diff             @@
##           master   #104031      +/-   ##
===========================================
+ Coverage   78.04%    80.44%   +2.39%     
===========================================
  Files        9313      9316       +3     
  Lines      397417    397506      +89     
  Branches    25373     25373              
===========================================
+ Hits       310178    319759    +9581     
+ Misses      86787     77295    -9492     
  Partials      452       452              

@ameliahsu ameliahsu merged commit 49fc969 into master Nov 26, 2025
96 of 98 checks passed
@ameliahsu ameliahsu deleted the mia/aci/detector_fake_alert_rule_id branch November 26, 2025 18:27
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.

3 participants