airflow: `context` doesn't contain `TaskIntance` when used in `on_*_callback` at the `DAG` level
Apache Airflow version
3.0.1
If “Other Airflow 2 version” selected, which one?
No response
What happened?
When using the on_*_callback at the dag level, the context that gets passed to the notify function only contains these keys
- dag
- run_id
- reason
When it’s called at a task level these keys are present
- dag
- inlets
- map_index_template
- outlets
- run_id
- task
- task_instance
- ti
- outlet_events
- inlet_events
- macros
- params
- var
- conn
- dag_run
- triggering_asset_events
- task_instance_key_str
- task_reschedule_count
- prev_start_date_success
- prev_end_date_success
- logical_date
- ds
- ds_nodash
- ts
- ts_nodash
- ts_nodash_with_tz
- data_interval_end
- data_interval_start
- prev_data_interval_start_success
- prev_data_interval_end_success
- templates_dict
What you think should happen instead?
The keys should be the same when used at a DAG level and a Task level, and should populated similarly, i.e., for task related keys should use the last task that completed in a DAG
How to reproduce
Create a custom notifier to be able to see the contents of context. Use the on_*_callback parameter at the DAG at task level using the TaskFlowAPI, not sure if this matters or not.
Operating System
Ubuntu
Versions of Apache Airflow Providers
No response
Deployment
Other Docker-based deployment
Deployment details
Custom docker container using apache/airflow:3.0.2rc1 as the base
Anything else?
No response
Are you willing to submit PR?
- Yes I am willing to submit a PR!
Code of Conduct
- I agree to follow this project’s Code of Conduct
About this issue
- Original URL
- State: open
- Created a year ago
- Comments: 15 (2 by maintainers)
@kiran2706, just wanted to check-in and see how things are going. Were you able to open up a PR for this?
Assigned!
Hi @jroachgolf84 👋,
I’d like to work on this issue and submit a PR that enhances the DAG-level
on_*_callbackcontext to optionally include additional fields likelog_url,try_number,max_tries, and potentially thetask_instanceof the last task that completed.Could you please assign this issue to me?
Thanks!