dor-bernstein opened a new issue, #77742:
URL: https://github.com/apache/airflow/issues/77742

   ### Apache Airflow version
   
   main (development); also 3.1.7 and 3.4.0
   
   ### What happened?
   
   When a trigger ends a deferred task with `TaskSuccessEvent`, 
`handle_event_submit` (`airflow-core/src/airflow/models/trigger.py`) always 
sends a `TaskCallbackRequest` with `task_callback_type=SUCCESS` to the Dag 
processor, whether or not the task has an `on_success_callback`.
   
   The Dag processor serves that request by loading the whole Dag file 
(`_parse_file` → `BundleDagBag(...)` → `_execute_callbacks`). Files with 
pending callbacks also go to the front of the parse queue. Then 
`_execute_task_callbacks` returns at once because the request isn't a failure 
callback:
   
   ```
   Task callback requested but is not a failure callback
   ```
   
   So every task a trigger ends as success costs one full parse of its Dag file 
and runs nothing. With many deferrable tasks ending this way (for example, 
`KubernetesPodOperator` tasks finishing from the trigger to avoid waiting for a 
pool slot again, see #57210), the extra parses add up and delay normal parsing 
of other files.
   
   ### What you think should happen instead?
   
   Skip the request when the task has no success callback. The serialized task 
already records `has_on_success_callback`, and the failure path in the same 
function already loads the serialized task to decide on retries, so the check 
is cheap.
   
   That keeps today's behavior for tasks that do define `on_success_callback` 
(the request is still sent), so it stays compatible with a later change that 
runs success callbacks for trigger-ended tasks (#46224).
   
   ### How to reproduce
   
   1. A deferrable operator whose trigger yields `TaskSuccessEvent()`, on a 
task with no `on_success_callback`.
   2. Run it and watch the Dag processor: the Dag file is parsed for the 
callback request and the log shows `Task callback requested but is not a 
failure callback`. The `dag_processing.other_callback_count` metric goes up 
once per task.
   
   ### Operating System
   
   Linux
   
   ### Deployment
   
   Official Apache Airflow Helm Chart
   
   ### Anything else?
   
   Related: #46224 (retries and callbacks for trigger-ended tasks; #69821 fixed 
failure/retry), #57210 (tasks returning from deferral wait for a pool slot 
again).
   
   ### Are you willing to submit a PR?
   
   - [x] Yes I am willing to submit a PR!


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