BranchPythonOperator selects downstream paths in an Airflow DAG by evaluating a Python callable. The callable returns one downstream task ID, or a list of task IDs when multiple branches should run. section 6.2.2
Choose between old and new ERP tasks
Create separate fetch and clean tasks for each ERP, then branch according to the DAG's execution date: def _pick_erp_system(**context): if context["data_interval_start"] < ERP_CHANGE_DATE: return "fetch_sales_old" return "fetch_sales_new" pick_erp_system = BranchPythonOperator( task_id="pick_erp_system", python_callable=_pick_erp_system, ) pick_erp_system >> [fetch_sales_old, fetch_sales_new] Connect the branch from the preceding start task. The returned task ID runs; the other branch is skipped.
Branching changes task states, so downstream joins need deliberate trigger rules. A join using the default all_success rule can be skipped when one branch is intentionally skipped; none_failed allows continuation when upstream tasks have not failed. section 6.2.2
Use these structural patterns when building a branch:
- Return a list of task IDs when several downstream paths should execute. section 6.2.2
