0
0
Apache Airflowdevops~10 mins

Default args and DAG parameters in Apache Airflow - Step-by-Step Execution

Choose your learning style9 modes available
Process Flow - Default args and DAG parameters
Define default_args dict
Create DAG with default_args
Define tasks using DAG
Run DAG
Tasks inherit default_args
Override parameters if needed
DAG executes with parameters
This flow shows how default arguments are set once and then used by all tasks in the DAG unless overridden.
Execution Sample
Apache Airflow
from datetime import datetime
from airflow import DAG

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

dag = DAG('example_dag', default_args=default_args, schedule_interval='@daily')
This code sets default arguments and creates a DAG that uses them for its tasks.
Process Table
StepActionParameter SetValueEffect
1Define default_argsownerairflowSets task owner to airflow
2Define default_argsstart_date2024-01-01Tasks start from this date
3Define default_argsretries1Tasks retry once on failure
4Create DAG with default_argsdefault_argsdefault_args dictDAG uses these defaults
5Define task1 without overrideownerairflowInherits from default_args
6Define task1 without overrideretries1Inherits from default_args
7Define task2 with overrideretries3Overrides default retries
8Run DAGtask1 retries1Task1 retries once
9Run DAGtask2 retries3Task2 retries thrice
10End--Execution complete
💡 All tasks run with parameters from default_args unless overridden explicitly.
Status Tracker
VariableStartAfter Step 5After Step 7Final
ownerundefinedairflowairflowairflow
start_dateundefined2024-01-012024-01-012024-01-01
retriesundefined13 (task2 override)varies by task
Key Moments - 2 Insights
Why does task2 retry 3 times but task1 only once?
Because task2 explicitly overrides the 'retries' parameter (see execution_table step 7), while task1 uses the default from default_args (step 5).
What happens if a parameter is missing in default_args?
If a parameter is missing in default_args and not set in the task, Airflow uses its internal defaults or may raise an error depending on the parameter.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what is the 'owner' value for task1 at step 5?
Aadmin
Bairflow
Cuser
Dundefined
💡 Hint
Check the 'Parameter Set' and 'Value' columns at step 5 in the execution_table.
At which step does task2 override the default 'retries' value?
AStep 5
BStep 6
CStep 7
DStep 8
💡 Hint
Look for the step mentioning 'Define task2 with override' in the execution_table.
If we remove 'retries' from default_args, what happens to task1 retries?
ARetries use Airflow default
BRetries become 3
CRetries become 0
DTask fails to run
💡 Hint
Refer to key_moments about missing parameters and Airflow's internal defaults.
Concept Snapshot
default_args is a dictionary of parameters set once for a DAG.
Tasks inherit these parameters unless overridden.
Common keys: owner, start_date, retries.
DAG uses default_args to apply consistent settings.
Overrides allow task-specific behavior.
This simplifies DAG management and reduces repetition.
Full Transcript
In Airflow, default_args is a dictionary that holds common parameters like owner, start_date, and retries. When you create a DAG, you pass default_args so all tasks inside inherit these settings automatically. This means you don't have to repeat the same parameters for every task. However, you can override any parameter for a specific task if needed. For example, if default_args sets retries to 1, but a task needs 3 retries, you override it in that task. This approach keeps your DAG clean and consistent. The execution table shows each step: defining default_args, creating the DAG, defining tasks with or without overrides, and running the DAG with the final parameters applied. Remember, if a parameter is missing in default_args and not set in a task, Airflow uses its own default values or may raise an error depending on the parameter.