Complete the code to create a BranchPythonOperator that decides the next task based on a condition.
branch_task = BranchPythonOperator(task_id='branching', python_callable=[1], dag=dag)
The python_callable parameter must be a function that returns the task_id to follow. Here, choose_branch is the function that handles the condition.
Complete the function to return the correct task_id based on the value of condition.
def choose_branch(): condition = True if condition: return [1] else: return 'task_b'
The function must return the task_id string of the next task to run. If condition is True, it returns 'task_a'.
Fix the error in the BranchPythonOperator definition by completing the missing parameter.
branch_task = BranchPythonOperator(task_id='branching', python_callable=choose_branch, [1]=dag)
schedule_interval instead of dagThe dag parameter links the operator to the DAG object. Without it, the task is not part of the DAG.
Fill both blanks to create a DAG with a BranchPythonOperator and two downstream tasks.
with DAG('branching_dag', start_date=days_ago(1), schedule_interval='@daily') as dag: branch = BranchPythonOperator(task_id='branch', python_callable=[1]) task_a = DummyOperator(task_id=[2]) task_b = DummyOperator(task_id='task_b') branch >> [task_a, task_b]
The python_callable must be the function choose_branch. The task_a DummyOperator must have the task_id 'task_a' to match the branch return value.
Fill all three blanks to define a branching function that returns different task_ids based on a variable.
def choose_branch(): value = 10 if value > [1]: return [2] else: return [3]
The function checks if value is greater than 5. If true, it returns 'task_high', else 'task_low'.