diff --git a/src/sentry/workflow_engine/processors/action.py b/src/sentry/workflow_engine/processors/action.py index cf14cb07da091b..b25980fdd18c71 100644 --- a/src/sentry/workflow_engine/processors/action.py +++ b/src/sentry/workflow_engine/processors/action.py @@ -2,6 +2,7 @@ from collections import defaultdict from datetime import datetime, timedelta +from django.db import models from django.utils import timezone from sentry import features @@ -183,8 +184,11 @@ def filter_recently_fired_workflow_actions( ) update_workflow_action_group_statuses(now, statuses_to_update, missing_statuses) - # TODO: somehow attach workflows so we can fire actions with the appropriate workflow env - return Action.objects.filter(id__in=list(action_to_workflow_ids.keys())) + return Action.objects.filter(id__in=list(action_to_workflow_ids.keys())).annotate( + workflow_id=models.F( + "dataconditiongroupaction__condition_group__workflowdataconditiongroup__workflow__id" + ) + ) def get_available_action_integrations_for_org(organization: Organization) -> list[RpcIntegration]: diff --git a/tests/sentry/workflow_engine/processors/test_action.py b/tests/sentry/workflow_engine/processors/test_action.py index e62df901fd24ad..6c8ba2c4941ec0 100644 --- a/tests/sentry/workflow_engine/processors/test_action.py +++ b/tests/sentry/workflow_engine/processors/test_action.py @@ -56,6 +56,9 @@ def test(self): set(DataConditionGroup.objects.all()), self.event_data ) assert set(triggered_actions) == {self.action} + assert {getattr(action, "workflow_id") for action in triggered_actions} == { + self.workflow.id, + } for status in [status_1, status_2]: status.refresh_from_db() @@ -103,6 +106,10 @@ def test_multiple_workflows_single_action__first_fire(self): ) # dedupes action if both workflows will fire it assert set(triggered_actions) == {self.action} + assert {getattr(action, "workflow_id") for action in triggered_actions} == { + self.workflow.id, + workflow.id, + } assert WorkflowActionGroupStatus.objects.filter(action=self.action).count() == 2 @@ -125,6 +132,10 @@ def test_multiple_workflows_single_action__later_fire(self): ) # fires one action for the workflow that can fire it assert set(triggered_actions) == {self.action} + assert {getattr(action, "workflow_id") for action in triggered_actions} == { + self.workflow.id, + workflow.id, + } assert WorkflowActionGroupStatus.objects.filter(action=self.action).count() == 2