From fedfaff1f3adfe0a13bf92d99112f7765d49a93e Mon Sep 17 00:00:00 2001 From: Raj Joshi Date: Tue, 17 Jun 2025 14:00:46 -0700 Subject: [PATCH 1/2] :bug: fix: annotate workflow_id on the action --- src/sentry/workflow_engine/processors/action.py | 7 ++++++- .../sentry/workflow_engine/processors/test_action.py | 11 +++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/sentry/workflow_engine/processors/action.py b/src/sentry/workflow_engine/processors/action.py index cf14cb07da091b..6e75891ffd4aff 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 @@ -184,7 +185,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 From eb9365fed5d8ad2f3955b6000b62cedcd05b4571 Mon Sep 17 00:00:00 2001 From: Raj Joshi Date: Tue, 17 Jun 2025 14:03:15 -0700 Subject: [PATCH 2/2] :bug: fix: comment --- src/sentry/workflow_engine/processors/action.py | 1 - 1 file changed, 1 deletion(-) diff --git a/src/sentry/workflow_engine/processors/action.py b/src/sentry/workflow_engine/processors/action.py index 6e75891ffd4aff..b25980fdd18c71 100644 --- a/src/sentry/workflow_engine/processors/action.py +++ b/src/sentry/workflow_engine/processors/action.py @@ -184,7 +184,6 @@ 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())).annotate( workflow_id=models.F( "dataconditiongroupaction__condition_group__workflowdataconditiongroup__workflow__id"