Airflow task context is the runtime collection of metadata and parameters made available while a task executes. Operators such as BashOperator template string arguments automatically; PythonOperator instead passes referenced context values into the callable. section 5.2.2
Use task context in three practical ways:
- Declare a specific parameter, such as data_interval_start, when the callable needs one known value. section 5.2.2
- Capture the complete context with **kwargs; naming it context communicates that the dictionary contains Airflow-provided values. section 5.2.2
- Read scheduling metadata such as logical_date, data_interval_start, and data_interval_end to construct time-specific behavior. section 5.3
Download data for the task interval
A PythonOperator callable receives logical_date through context, extracts its year, month, day, and hour, and builds the corresponding Wikimedia page-views URL. This keeps the download aligned with the task's scheduled time.
Conditionally deploy the latest model
A deployment callable receives the DAG and interval boundaries, asks the timetable for the next DAG run, and deploys only when execution falls within the latest interval. This approach works around the unavailable next_data_interval_end value. section 6.3.1
