Bird
Raised Fist0
Apache Airflowdevops~20 mins

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

Choose your learning style10 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.

Practice

(1/5)
1. What is the main purpose of default_args in an Airflow DAG?
easy
A. To define the schedule interval of the DAG
B. To specify the Python version used by the DAG
C. To set common parameters like retries and owner for all tasks
D. To list all the tasks in the DAG

Solution

  1. Step 1: Understand the role of default_args

    default_args is a dictionary used to set common settings for tasks, such as retries, owner, start date, etc.
  2. Step 2: Differentiate from DAG parameters

    DAG parameters like schedule_interval control when the DAG runs, not task defaults.
  3. Final Answer:

    To set common parameters like retries and owner for all tasks -> Option C
  4. Quick Check:

    default_args = common task settings [OK]
Hint: default_args sets task defaults, not DAG schedule [OK]
Common Mistakes:
  • Confusing default_args with DAG schedule_interval
  • Thinking default_args lists tasks
  • Assuming default_args sets Python version
2. Which of the following is the correct way to define default_args with retries set to 3 and owner as 'airflow'?
easy
A. default_args = {'retries': 3, 'owner': 'airflow'}
B. default_args = ['retries=3', 'owner=airflow']
C. default_args = (retries=3, owner='airflow')
D. default_args = retries:3, owner:'airflow'

Solution

  1. Step 1: Recall Python dictionary syntax

    Python dictionaries use curly braces with key:value pairs, keys as strings and values properly quoted if strings.
  2. Step 2: Check each option's syntax

    default_args = {'retries': 3, 'owner': 'airflow'} uses correct dictionary syntax. Options A, B, and D use invalid Python syntax for dictionaries.
  3. Final Answer:

    default_args = {'retries': 3, 'owner': 'airflow'} -> Option A
  4. Quick Check:

    Python dict = curly braces with key:value [OK]
Hint: default_args is a Python dict with keys and values [OK]
Common Mistakes:
  • Using list or tuple instead of dict
  • Missing quotes around string keys or values
  • Using colon instead of equal sign inside dict
3. Given this DAG snippet:
default_args = {'owner': 'admin', 'retries': 2}
with DAG('example_dag', default_args=default_args, schedule_interval='@daily') as dag:
    task1 = BashOperator(task_id='task1', bash_command='echo Hello')
    task2 = BashOperator(task_id='task2', bash_command='echo World', retries=5)

What is the number of retries for task2?
medium
A. 5
B. 2
C. 0
D. Undefined, causes error

Solution

  1. Step 1: Understand default_args and task-level override

    default_args sets retries=2 for all tasks unless overridden.
  2. Step 2: Check task2 retries parameter

    task2 explicitly sets retries=5, which overrides the default.
  3. Final Answer:

    5 -> Option A
  4. Quick Check:

    Task-level retries override default_args [OK]
Hint: Task args override default_args if set [OK]
Common Mistakes:
  • Assuming default_args always applies
  • Thinking task2 inherits retries=2
  • Confusing retries with schedule_interval
4. You wrote this DAG code:
default_args = {'owner': 'user', 'start_date': '2023-01-01'}
dag = DAG('my_dag', default_args=default_args, schedule_interval='@hourly')

But Airflow throws an error about start_date. What is the likely problem?
medium
A. owner cannot be 'user', must be 'airflow'
B. schedule_interval '@hourly' is invalid syntax
C. default_args must be passed as a list, not dict
D. start_date must be a datetime object, not a string

Solution

  1. Step 1: Check start_date type requirement

    Airflow requires start_date to be a datetime object, not a string.
  2. Step 2: Validate other parameters

    schedule_interval='@hourly' is valid, default_args is a dict, and owner can be any string.
  3. Final Answer:

    start_date must be a datetime object, not a string -> Option D
  4. Quick Check:

    start_date = datetime, not string [OK]
Hint: Use datetime objects for start_date in default_args [OK]
Common Mistakes:
  • Passing start_date as string instead of datetime
  • Misunderstanding schedule_interval format
  • Thinking owner must be 'airflow'
5. You want a DAG to run every Monday at 9 AM starting from March 1, 2024, with tasks retrying twice on failure and owned by 'data_team'. Which default_args and DAG parameters are correct?
hard
A. default_args = {'owner': 'data_team', 'retries': 2, 'start_date': '2024-03-01 09:00'}\ndag = DAG('weekly_dag', default_args=default_args, schedule_interval='0 9 * * 1')
B. default_args = {'owner': 'data_team', 'retries': 2, 'start_date': datetime(2024, 3, 1)}\ndag = DAG('weekly_dag', default_args=default_args, schedule_interval='0 9 * * 1')
C. default_args = {'owner': 'data_team', 'retries': 2, 'start_date': datetime(2024, 3, 1, 9, 0)}\ndag = DAG('weekly_dag', default_args=default_args, schedule_interval='@daily')
D. default_args = {'owner': 'data_team', 'retries': 2, 'start_date': '2024-03-01 09:00'}\ndag = DAG('weekly_dag', default_args=default_args, schedule_interval='@weekly')

Solution

  1. Step 1: Set start_date with datetime object

    Start date must be a datetime object; time can be set to midnight if not specified.
  2. Step 2: Use correct cron for Monday 9 AM

    Cron '0 9 * * 1' means 9 AM every Monday, matching requirement.
  3. Step 3: Check retries and owner in default_args

    Retries=2 and owner='data_team' are correctly set.
  4. Final Answer:

    default_args with datetime(2024, 3, 1) and schedule_interval='0 9 * * 1' -> Option B
  5. Quick Check:

    start_date datetime + cron for Monday 9 AM [OK]
Hint: Use cron '0 9 * * 1' for Monday 9 AM schedule [OK]
Common Mistakes:
  • Using string for start_date
  • Using '@weekly' which runs Sunday midnight
  • Setting schedule_interval to '@daily' instead of Monday
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard