-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
fix(aci): handle fake alert rule ids in AlertRuleDetector lookup #104031
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,6 +16,7 @@ | |
| RESPONSE_UNAUTHORIZED, | ||
| ) | ||
| from sentry.apidocs.parameters import GlobalParams | ||
| from sentry.incidents.endpoints.serializers.utils import get_object_id_from_fake_id | ||
| from sentry.models.organization import Organization | ||
| from sentry.workflow_engine.endpoints.serializers.alertrule_detector_serializer import ( | ||
| AlertRuleDetectorSerializer, | ||
|
|
@@ -24,6 +25,7 @@ | |
| AlertRuleDetectorValidator, | ||
| ) | ||
| from sentry.workflow_engine.models.alertrule_detector import AlertRuleDetector | ||
| from sentry.workflow_engine.models.detector import Detector | ||
|
|
||
|
|
||
| @region_silo_endpoint | ||
|
|
@@ -69,7 +71,26 @@ def get(self, request: Request, organization: Organization) -> Response: | |
| queryset = queryset.filter(rule_id=rule_id) | ||
|
|
||
| alert_rule_detector = queryset.first() | ||
| if not alert_rule_detector: | ||
| raise ResourceDoesNotExist | ||
|
|
||
| return Response(serialize(alert_rule_detector, request.user)) | ||
| if alert_rule_detector: | ||
| return Response(serialize(alert_rule_detector, request.user)) | ||
|
|
||
| # Fallback: if alert_rule_id was provided but no AlertRuleDetector was found, | ||
| # try looking up Detector directly using calculated detector_id | ||
| if alert_rule_id: | ||
| try: | ||
| 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, | ||
| } | ||
|
Comment on lines
82
to
93
This comment was marked as outdated.
Sorry, something went wrong. |
||
| ) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bug: Fallback ignores detector_id and rule_id filtersThe fallback logic activates whenever |
||
| except (ValueError, Detector.DoesNotExist): | ||
| pass | ||
|
|
||
| raise ResourceDoesNotExist | ||
Uh oh!
There was an error while loading. Please reload this page.