Skip to content

Defaults

DAG Factory allows you to define Airflow default_args and additional DAG-level arguments in a default block. This block enables you to share common settings across all DAGs in your YAML configuration, with the arguments automatically applied to each DAG defined in the file.

Benefits of using the default block

  • Consistency: Ensures uniform configurations across all tasks and DAGs.
  • Maintainability: Reduces duplication by centralizing common properties.
  • Simplicity: Makes configurations easier to read and manage.

Example usage of default block

Usage of default block in YAML
default:
  default_args:
    owner: default_owner
    retries: 1
    retry_delay_sec: 300
    start_date: 2024-01-01
  default_view: tree
  max_active_runs: 1
  schedule_interval: 0 1 * * *
example_task_group:
  description: "this dag uses task groups"
  task_groups:
    task_group_1:
      tooltip: "this is a task group"
      dependencies: [task_1]
    task_group_2:
      tooltip: "this is a task group"
      parent_group_name: task_group_1
  tasks:
    task_1:
      operator: airflow.operators.bash_operator.BashOperator
      bash_command: "echo 1"
    task_2:
      operator: airflow.operators.bash_operator.BashOperator
      bash_command: "echo 2"
      task_group_name: task_group_1
    task_4:
      operator: airflow.operators.bash_operator.BashOperator
      bash_command: "echo 4"
      task_group_name: task_group_2

The arguments specified in the default block, such as default_args, default_view, max_active_runs, schedule_interval, and any others defined, will be applied to all the DAGs in the YAML configuration.

Multiple ways for specifying Airflow default_args

DAG Factory offers flexibility in defining Airflow’s default_args. These can be specified in several ways, depending on your requirements.

  1. Specifying default_args in the default block

    As seen in the previous example, you can define shared default_args for all DAGs in the configuration YAML under the default block. These arguments are automatically inherited by every DAG defined in the file.

  2. Specifying default_args directly in a DAG configuration

    You can override or define specific default_args at the individual DAG level. This allows you to customize arguments for each DAG without affecting others.

    Example:

    DAG level default_args
    default:
      default_args:
        catchup: false,
        start_date: 2024-11-11
    
    basic_example_dag:
      default_args:
        owner: "custom_owner"
      description: "this is an example dag"
      schedule_interval: "0 3 * * *"
      render_template_as_native_obj: True
      tasks:
        task_1:
          operator: airflow.operators.bash_operator.BashOperator
          bash_command: "echo 1"
        task_2:
          operator: airflow.operators.bash_operator.BashOperator
          bash_command: "echo 2"
          dependencies: [task_1]
        task_3:
          operator: airflow.operators.bash_operator.BashOperator
          bash_command: "echo 2"
          dependencies: [task_1]
    
  3. Specifying default_args in a shared defaults.yml

    Starting DAG Factory 0.22.0, you can also keep the default_args in the defaults.yml file. The configuration from defaults.yml will be applied to all DAG Factory generated DAGs.

    defaults.yml
    default_args:
      start_date: "2025-01-01"
      owner: "global_owner"
    

Given the various ways to specify default_args, the following precedence order is applied when arguments are duplicated:

  1. In the DAG configuration
  2. In the default block within the workflow's YAML file
  3. In the defaults.yml