Task Groups help organize related tasks visually in the Airflow UI, making complex DAGs easier to understand. They do not change execution behavior or dependencies.
from airflow import DAG from airflow.operators.dummy import DummyOperator from airflow.utils.task_group import TaskGroup from datetime import datetime default_args = {'start_date': datetime(2024, 1, 1)} dag = DAG('example_dag', default_args=default_args, schedule_interval='@daily') start = DummyOperator(task_id='start', dag=dag) end = DummyOperator(task_id='end', dag=dag) with TaskGroup('group1', dag=dag) as group1: t1 = DummyOperator(task_id='task1') t2 = DummyOperator(task_id='task2') start >> group1 >> end
Task Groups appear as a single collapsible node in the Airflow UI. Inside, the grouped tasks are shown. The sequence is start → group1 → end.
The correct way is to create a TaskGroup instance, then use it as a context manager to define tasks inside. Option A does this correctly.
Task Groups must be defined inside a DAG context or passed a DAG explicitly. Otherwise, Airflow raises an AirflowException indicating the missing DAG context.
groupA >> groupB, what is the effect on the tasks inside these groups?Setting groupA >> groupB creates dependencies from every task in groupA to every task in groupB, so all groupA tasks must finish before groupB tasks start.