0
0
Apache Airflowdevops~20 mins

Default args and DAG parameters in Apache Airflow - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Default Args & DAG Parameters Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
What is the start_date of the DAG?
Given this Airflow DAG snippet, what is the effective start_date of the DAG tasks?

default_args = {
  'owner': 'airflow',
  'start_date': datetime(2024, 1, 1)
}

dag = DAG(
  'example_dag',
  default_args=default_args,
  start_date=datetime(2024, 2, 1),
  schedule_interval='@daily'
)
Apache Airflow
from datetime import datetime
from airflow import DAG

default_args = {
  'owner': 'airflow',
  'start_date': datetime(2024, 1, 1)
}

dag = DAG(
  'example_dag',
  default_args=default_args,
  start_date=datetime(2024, 2, 1),
  schedule_interval='@daily'
)
AThe start_date is the current date when DAG runs
B2024-02-01
CThe DAG has no start_date, so it will fail
D2024-01-01
Attempts:
2 left
💡 Hint
The DAG parameter start_date overrides the one in default_args.
🧠 Conceptual
intermediate
2:00remaining
What happens if a task has no start_date but DAG has one?
In Airflow, if a DAG has a start_date defined but a task inside it does not specify any start_date, what will be the task's effective start_date?

Choose the correct behavior.
AThe task inherits the DAG's start_date
BThe task will fail to run due to missing start_date
CThe task uses the current date as start_date
DThe task uses the earliest start_date from default_args
Attempts:
2 left
💡 Hint
Tasks inherit missing parameters from DAG or default_args.
Configuration
advanced
2:00remaining
Identify the error in this DAG default_args usage
Examine the following DAG code snippet. What error will occur when Airflow tries to parse this DAG?

default_args = {
  'owner': 'airflow',
  'start_date': '2024-01-01'
}

dag = DAG(
  'faulty_dag',
  default_args=default_args,
  schedule_interval='@daily'
)
Apache Airflow
from datetime import datetime
from airflow import DAG
default_args = {
  'owner': 'airflow',
  'start_date': '2024-01-01'
}
dag = DAG(
  'faulty_dag',
  default_args=default_args,
  schedule_interval='@daily'
)
ANo error, DAG will run fine
BSyntaxError due to missing comma
CTypeError: start_date must be a datetime object, not string
DValueError: schedule_interval is invalid
Attempts:
2 left
💡 Hint
Check the type of the start_date value.
🔀 Workflow
advanced
2:30remaining
Order the steps to override default_args in a DAG
Put these steps in the correct order to override a default argument in an Airflow DAG.

Steps:
1. Pass the new argument value directly in the DAG constructor
2. Define default_args dictionary with base parameters
3. Create the DAG object with default_args parameter
4. Import required modules and datetime
A1,2,3,4
B4,2,3,1
C1,3,2,4
D2,1,4,3
Attempts:
2 left
💡 Hint
Start with imports, then define defaults, create DAG, then override.
Troubleshoot
expert
3:00remaining
Why does this DAG fail to schedule despite correct start_date?
You have this DAG snippet:

default_args = {
  'owner': 'airflow',
  'start_date': datetime(2024, 4, 1)
}

dag = DAG(
  'test_dag',
  default_args=default_args,
  schedule_interval='@daily',
  catchup=False
)

# Task definition omitted for brevity

The DAG never runs any tasks even after 2024-04-01. What is the most likely reason?
Apache Airflow
from datetime import datetime
from airflow import DAG
default_args = {
  'owner': 'airflow',
  'start_date': datetime(2024, 4, 1)
}
dag = DAG(
  'test_dag',
  default_args=default_args,
  schedule_interval='@daily',
  catchup=False
)
Aschedule_interval '@daily' is invalid and prevents scheduling
Bcatchup=False disables all runs permanently
CMissing task definitions cause DAG to not run
DThe DAG start_date is in the future relative to the scheduler's current date
Attempts:
2 left
💡 Hint
Check the system date vs start_date.