Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to import the Airflow DAG class.
Apache Airflow
from airflow.models import [1]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Importing TaskInstance instead of DAG
Using BaseOperator which is for tasks
✗ Incorrect
The DAG class is imported from airflow.models to define workflows.
2fill in blank
mediumComplete the code to create a DAG object with id 'test_dag'.
Apache Airflow
dag = [1](dag_id='test_dag', start_date=datetime(2024, 1, 1))
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using BaseOperator instead of DAG
Forgetting to set dag_id
✗ Incorrect
The DAG object is created by calling DAG() with parameters like dag_id and start_date.
3fill in blank
hardFix the error in the test code to check if the DAG has the correct id.
Apache Airflow
assert dag.[1] == 'test_dag'
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using id or name instead of dag_id
Trying to access dag_name which is invalid
✗ Incorrect
The DAG's unique identifier is accessed via the dag_id attribute.
4fill in blank
hardFill both blanks to create a task using PythonOperator with a simple callable.
Apache Airflow
task = PythonOperator(task_id='print_hello', python_callable=[1], dag=[2])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using print instead of a function name
Passing start_date instead of dag
✗ Incorrect
The python_callable parameter expects a function like print_hello, and dag is the DAG object.
5fill in blank
hardFill all three blanks to assert the task has the correct task_id and belongs to the DAG.
Apache Airflow
assert task.[1] == 'print_hello' assert task.[2] == [3]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using dag_id instead of dag for task's DAG
Mixing up attribute names
✗ Incorrect
Task's task_id attribute holds its id, and dag attribute links to the DAG object.