You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Add a way to differentiate between a task/DAG-level callback by context #61119
Currently, the context passed to a callback defined on DAG level looks pretty much the same as a context passed to a task callback. Thus, we the callback's code doesn't have a way to differentiate between the two cases (from experimentation I noted that the task-level callback has an exception field while the DAG callback doesn't, but it doesn't look reliable enough).
I expected the DAG-level callback to not have a task_instance field, but apparently it points to the last task executed.
I propose injecting a new field into the context that points to the parent object (TI or DAG) that caused the callback to be called / enum that signifies whether it's a task or a dag level callback.
Current workaround is writing a callback class that has a boolean flag and use partial when initializing it for DAG/task.
Use case/motivation
In my callback code I want to know which kind of callback was triggered and handle a failure accordingly.
Activity
IndiTheo commentedon Jan 27, 2026
I'd like to work on this
jroachgolf84 commentedon Jan 27, 2026
@Asquator, please feel free to open up a PR for this issue.
tirkarthi commentedon Jan 27, 2026
Related #26760
IndiTheo commentedon Jan 27, 2026
Found out that the context you see in DAG callbacks consists of task details of the last task in the DAG by lexicographical order - #26760 (comment)
I think it's worth starting from changing this behavior and then adding some differentiation criteria (documenting it too)
Add callback_source to context to differentiate DAG vs task callbacks
Add `callback` and `source` to context to differentiate between Dag a…