Challenge - 5 Problems
BranchPythonOperator Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate2:00remaining
Output of BranchPythonOperator with conditional branching
Given the following Airflow DAG snippet using BranchPythonOperator, what will be the output of the task
branch_task when execution_date.day is 15?Apache Airflow
def choose_branch(**kwargs): day = kwargs['execution_date'].day if day < 10: return 'task_a' else: return 'task_b' branch_task = BranchPythonOperator( task_id='branch_task', python_callable=choose_branch, provide_context=True, dag=dag )
Attempts:
2 left
💡 Hint
Check the condition comparing the day of execution_date to 10.
✗ Incorrect
The function returns 'task_b' because the day (15) is not less than 10, so the else branch is taken.
🧠 Conceptual
intermediate1:30remaining
Understanding BranchPythonOperator behavior
What happens to downstream tasks that are not returned by the BranchPythonOperator's callable?
Attempts:
2 left
💡 Hint
Think about how branching controls the flow of tasks.
✗ Incorrect
BranchPythonOperator skips all downstream tasks except those returned by its callable function.
🔀 Workflow
advanced2:30remaining
Correct order of task execution with BranchPythonOperator
Arrange the following tasks in the order they execute in an Airflow DAG with a BranchPythonOperator named
branch_task that chooses between task_a and task_b. The DAG starts with start_task and ends with end_task.Attempts:
2 left
💡 Hint
BranchPythonOperator runs after the start and before the chosen task.
✗ Incorrect
The DAG runs start_task first, then branch_task decides which task to run next (task_a or task_b), then finally end_task.
❓ Troubleshoot
advanced2:00remaining
Error caused by BranchPythonOperator returning invalid task_id
What error will Airflow raise if the BranchPythonOperator's callable returns a task_id that does not exist in the DAG?
Attempts:
2 left
💡 Hint
Consider what happens when the DAG tries to find a task by a name that is missing.
✗ Incorrect
Airflow raises an AirflowException because it cannot find the task_id returned by the BranchPythonOperator in the DAG's task dictionary.
✅ Best Practice
expert3:00remaining
Best practice for multiple branches in BranchPythonOperator
Which approach is best to handle multiple possible branches in a BranchPythonOperator to ensure all branches are valid and maintainable?
Attempts:
2 left
💡 Hint
BranchPythonOperator supports returning multiple task_ids as a list.
✗ Incorrect
Returning a list of valid task_ids allows branching to multiple tasks cleanly and is supported by Airflow.