Challenge - 5 Problems
Dynamic Task Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate2:00remaining
Output of dynamically generated Airflow tasks with loop
Given the following Airflow DAG snippet, what will be the output when the DAG is parsed and tasks are listed?
Apache Airflow
from airflow import DAG from airflow.operators.dummy import DummyOperator from datetime import datetime with DAG('loop_dag', start_date=datetime(2024, 1, 1)) as dag: tasks = [] for i in range(3): task = DummyOperator(task_id=f'task_{i}') tasks.append(task) print([task.task_id for task in tasks])
Attempts:
2 left
💡 Hint
Remember that range(3) generates numbers 0, 1, 2.
✗ Incorrect
The loop runs 3 times with i values 0, 1, and 2, creating tasks with those IDs.
🔀 Workflow
intermediate2:30remaining
Correct order of dynamic task dependencies in Airflow
Arrange the following code lines to correctly create a chain of tasks dynamically in Airflow using a loop.
Attempts:
2 left
💡 Hint
The loop must start first, then create task, set dependency, then update previous_task.
✗ Incorrect
The loop starts, creates a task, sets dependency from previous_task to current task, then updates previous_task for next iteration.
❓ Troubleshoot
advanced2:00remaining
Error caused by dynamic task creation in Airflow
What error will this Airflow DAG code raise when parsing, and why?
from airflow import DAG
from airflow.operators.dummy import DummyOperator
from datetime import datetime
with DAG('error_dag', start_date=datetime(2024, 1, 1)) as dag:
for i in range(3):
task = DummyOperator(task_id='task')
Attempts:
2 left
💡 Hint
Task IDs must be unique in an Airflow DAG.
✗ Incorrect
All tasks have the same task_id 'task', which is not allowed and causes a validation error.
🧠 Conceptual
advanced1:30remaining
Best practice for dynamic task creation in Airflow
Which statement best describes a best practice when generating tasks dynamically in Airflow using loops?
Attempts:
2 left
💡 Hint
Think about how Airflow identifies tasks uniquely.
✗ Incorrect
Unique task_ids are required for Airflow to distinguish tasks and avoid errors.
✅ Best Practice
expert3:00remaining
Handling dynamic task dependencies with variable task counts
You want to create a dynamic chain of tasks in Airflow where the number of tasks is not fixed and depends on external input. Which approach ensures the chain is correctly built regardless of the number of tasks?
Attempts:
2 left
💡 Hint
Think about how to link tasks dynamically when you don't know how many there will be.
✗ Incorrect
Initializing previous_task as None and updating it inside the loop allows chaining tasks dynamically regardless of count.