Skip to content

Commit 1446e79

Browse files
authored
fix(aci): allow creating issue alerts with no triggers (#87189)
1 parent 923d715 commit 1446e79

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

src/sentry/workflow_engine/migration_helpers/issue_alert_migration.py

+8-3
Original file line numberDiff line numberDiff line change
@@ -191,13 +191,18 @@ def _create_workflow_and_lookup(
191191

192192
# the only time the data_conditions list will be empty is if somebody only has EveryEventCondition in their conditions list.
193193
# if it's empty and this is not the case, we should not migrate
194-
no_conditions = len(data_conditions) == 0
194+
no_conditions = len(conditions) == 0
195+
no_data_conditions = len(data_conditions) == 0
195196
only_has_every_event_cond = (
196197
len(conditions) == 1 and conditions[0]["id"] == EveryEventCondition.id
197198
)
198199

199-
if not self.is_dry_run and no_conditions and not only_has_every_event_cond:
200-
raise Exception("No valid conditions, skipping migration")
200+
if not self.is_dry_run:
201+
if no_data_conditions and no_conditions:
202+
# originally no conditions and we expect no data conditions
203+
pass
204+
elif no_data_conditions and not only_has_every_event_cond:
205+
raise Exception("No valid trigger conditions, skipping migration")
201206

202207
enabled = True
203208
rule_snooze = RuleSnooze.objects.filter(rule=self.rule, user_id=None).first()

tests/sentry/workflow_engine/migration_helpers/test_issue_alert_migration.py

+14
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,20 @@ def test_run__skip_migration_if_no_valid_conditions(self):
290290

291291
assert Workflow.objects.all().count() == 0
292292

293+
def test_run__no_triggers(self):
294+
self.issue_alert.data["conditions"] = []
295+
self.issue_alert.save()
296+
297+
IssueAlertMigrator(self.issue_alert, self.user.id, should_create_actions=False).run()
298+
299+
issue_alert_workflow = AlertRuleWorkflow.objects.get(rule=self.issue_alert)
300+
workflow = Workflow.objects.get(id=issue_alert_workflow.workflow.id)
301+
302+
assert workflow.when_condition_group
303+
assert (
304+
DataCondition.objects.filter(condition_group=workflow.when_condition_group).count() == 0
305+
)
306+
293307
def test_run__no_double_migrate(self):
294308
IssueAlertMigrator(self.issue_alert, self.user.id).run()
295309

0 commit comments

Comments
 (0)