Copilot commented on code in PR #77741:
URL: https://github.com/apache/airflow/pull/77741#discussion_r4734995064


##########
airflow-core/src/airflow/models/trigger.py:
##########
@@ -945,10 +946,19 @@ def _(event: BaseTaskEndEvent, *, task_instance: 
TaskInstance, session: Session)
             )
         if should_retry:
             callback_type = TaskInstanceState.UP_FOR_RETRY
+    elif event.task_instance_state == TaskInstanceState.SUCCESS:
+        # The Dag processor parses the whole Dag file to serve a callback 
request, so skip the
+        # request when the task has no success callback to run.
+        try:
+            dag = dag_bag.get_dag_for_run(dag_run=task_instance.dag_run, 
session=session)
+            if dag is not None:
+                needs_callback = 
dag.get_task(task_instance.task_id).has_on_success_callback

Review Comment:
   This lookup deserializes the entire Dag for every successful task instance: 
`DBDagBag` is created afresh in this per-task handler, and 
`SerializedDagModel.dag` reconstructs the Dag on each cache miss. When one 
trigger ends N tasks from an M-task Dag, the new success path therefore 
reconstructs M tasks N times in the synchronous triggerer event loop, delaying 
unrelated trigger events. Please reuse a Dag bag across the event's task 
instances, or retrieve the serialized callback flag without deserializing the 
whole Dag each time.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to