Skip to content

context doesn't contain TaskIntance when used in on_*_callback at the DAG level #51402

@jnstockley

Description

@jnstockley

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

Metadata

Metadata

Assignees

Labels

area:corekind:bugThis is a clearly a bugpriority:lowBug with a simple workaround that would not block a release

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions