dor-bernstein commented on code in PR #77741:
URL: https://github.com/apache/airflow/pull/77741#discussion_r4736580728


##########
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:
   Fixed in 6bb55374. `Trigger.submit_event` now builds one `DBDagBag` per 
event and passes it to `handle_event_submit` for every task instance. 
`DBDagBag` caches by Dag version, so a trigger that ends N tasks of one Dag 
deserializes it once rather than N times. Other callers of 
`handle_event_submit` (the scheduler, the execution API and HITL routes, and 
the common.ai provider) are unchanged: the task-end handler falls back to a 
fresh bag when none is passed. Added 
`test_submit_event_task_end_success_loads_the_dag_once_per_event`, which counts 
`_read_dag` calls for two task instances ended by one event.



-- 
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