@@ -67,7 +67,6 @@ def build_trigger_action_task_params(
6767@retry (timeouts = True , raise_on_no_retries = False , ignore_and_capture = Action .DoesNotExist )
6868def trigger_action (
6969 action_id : int ,
70- detector_id : int ,
7170 workflow_id : int ,
7271 event_id : str | None ,
7372 activity_id : int | None ,
@@ -76,8 +75,10 @@ def trigger_action(
7675 group_state : GroupState ,
7776 has_reappeared : bool ,
7877 has_escalated : bool ,
78+ detector_id : int | None = None ,
7979) -> None :
8080 from sentry .notifications .notification_action .utils import should_fire_workflow_actions
81+ from sentry .workflow_engine .processors .detector import get_detector_from_event_data
8182
8283 # XOR check to ensure exactly one of event_id or activity_id is provided
8384 if (event_id is not None ) == (activity_id is not None ):
@@ -88,19 +89,14 @@ def trigger_action(
8889 raise ValueError ("Exactly one of event_id or activity_id must be provided" )
8990
9091 action = Action .objects .annotate (workflow_id = Value (workflow_id )).get (id = action_id )
91- detector = Detector .objects .get (id = detector_id )
9292
93- metrics .incr (
94- "workflow_engine.tasks.trigger_action_task_started" ,
95- tags = {"action_type" : action .type , "detector_type" : detector .type },
96- sample_rate = 1.0 ,
97- )
98-
99- project_id = detector .project_id
93+ # TODO: remove detector usage from this task
94+ detector : Detector | None = None
95+ if detector_id is not None :
96+ detector = Detector .objects .get (id = detector_id )
10097
10198 if event_id is not None :
10299 event_data = build_workflow_event_data_from_event (
103- project_id = project_id ,
104100 event_id = event_id ,
105101 group_id = group_id ,
106102 workflow_id = workflow_id ,
@@ -109,7 +105,6 @@ def trigger_action(
109105 has_reappeared = has_reappeared ,
110106 has_escalated = has_escalated ,
111107 )
112-
113108 elif activity_id is not None :
114109 event_data = build_workflow_event_data_from_activity (
115110 activity_id = activity_id , group_id = group_id
@@ -122,6 +117,15 @@ def trigger_action(
122117 )
123118 raise ValueError ("Exactly one of event_id or activity_id must be provided" )
124119
120+ if not detector :
121+ detector = get_detector_from_event_data (event_data )
122+
123+ metrics .incr (
124+ "workflow_engine.tasks.trigger_action_task_started" ,
125+ tags = {"action_type" : action .type , "detector_type" : detector .type },
126+ sample_rate = 1.0 ,
127+ )
128+
125129 should_trigger_actions = should_fire_workflow_actions (
126130 detector .project .organization , event_data .group .type
127131 )
@@ -130,7 +134,7 @@ def trigger_action(
130134 # Set up a timeout grouping context because we want to make sure any Sentry timeout reporting
131135 # in this scope is grouped properly.
132136 with timeout_grouping_context (action .type ):
133- action .trigger (event_data , detector )
137+ action .trigger (event_data )
134138 else :
135139 logger .info (
136140 "workflow_engine.triggered_actions.dry-run" ,
0 commit comments