Skip to content

Commit

Permalink
ref(alerts): Move anomaly detection feature check (#78652)
Browse files Browse the repository at this point in the history
Don't ask me why I had it where it was before, but it doesn't make sense
to create the alert at all if the feature isn't available.
  • Loading branch information
ceorourke authored Oct 4, 2024
1 parent 6899ecf commit fa80f0d
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/sentry/incidents/logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -564,6 +564,13 @@ def create_alert_rule(
:return: The created `AlertRule`
"""
has_anomaly_detection = features.has(
"organizations:anomaly-detection-alerts", organization
) and features.has("organizations:anomaly-detection-rollout", organization)

if detection_type == AlertRuleDetectionType.DYNAMIC.value and not has_anomaly_detection:
raise ResourceDoesNotExist("Your organization does not have access to this feature.")

if monitor_type == AlertRuleMonitorTypeInt.ACTIVATED and not activation_condition:
raise ValidationError("Activation condition required for activated alert rule")

Expand Down Expand Up @@ -647,13 +654,6 @@ def create_alert_rule(
AlertRuleExcludedProjects.objects.bulk_create(exclusions)

if alert_rule.detection_type == AlertRuleDetectionType.DYNAMIC.value:
if not features.has(
"organizations:anomaly-detection-alerts", organization
) and not features.has("organizations:anomaly-detection-rollout", organization):
alert_rule.delete()
raise ResourceDoesNotExist(
"Your organization does not have access to this feature."
)
# NOTE: if adding a new metric alert type, take care to check that it's handled here
send_new_rule_data(alert_rule, projects[0], snuba_query)

Expand Down

0 comments on commit fa80f0d

Please sign in to comment.