feat(ACI): Dual delete Workflow/Rule if flag enabled#110003
feat(ACI): Dual delete Workflow/Rule if flag enabled#110003
Conversation
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
| data=rule.get_audit_log_data(), | ||
| transaction_id=scheduled.id, | ||
| ) | ||
| except (AlertRuleWorkflow.DoesNotExist, Rule.DoesNotExist): |
There was a problem hiding this comment.
Unhandled MultipleObjectsReturned in AlertRuleWorkflow lookup
Medium Severity
AlertRuleWorkflow.objects.get(workflow_id=rule.id) can raise MultipleObjectsReturned, which isn't caught by the except clause on line 452. The AlertRuleWorkflow model's unique_together constraints are on (workflow, rule_id) and (workflow, alert_rule_id) pairs, not on workflow alone, so a single workflow_id can have multiple rows (one linking a rule_id, another linking an alert_rule_id). This would cause a 500 error after the Workflow has already been successfully marked for deletion. Filtering with rule_id__isnull=False or using filter().first() would be safer.
There was a problem hiding this comment.
I am pretty sure we don't have anything in the db like that


Try to look up the related
Ruleobject and delete that as well if we are passed a workflow to the issue alert rule delete method. In #109752 I assumed we'd always be getting a single written workflow but that may not always be the case.