Skip to content

Dynamic DAG Params behaves differently in manually triggered run vs scheduled run.  #39904

@jianqiuhuang

Description

@jianqiuhuang

Apache Airflow version

Other Airflow 2 version (please specify below)

If "Other Airflow 2 version" selected, which one?

2.7.2

What happened?

Dynamic DAG Params behaves differently in manually triggered run vs scheduled run.

  • For manually triggered run, the UI calculates the DAG conf Parameters and populate the values in the Trigger DAG page. The values are then fixed in the DAG run.
  • For scheduled run, Airflow re-evaluates Params for each task run. This is unexpected and different from manually triggered run behavior

What you think should happen instead?

Scheduled run should behave the same as manually triggered run. i.e. the value of DAG level Params should only be evaluated once.

How to reproduce

  1. Create a simple DAG that contains a DAG-level Param using `pendulum.now("America/Los_Angeles")
import pendulum
from airflow.models.dag import DAG
from airflow.models.param import Param
from airflow.operators.python import PythonOperator


def print_param(date, **context):
    print(date)


with DAG(
    dag_id="test_param_behavior",
    start_date=pendulum.datetime(2024, 4, 16, tz="America/Los_Angeles"),
    schedule='0 * * * *',
    catchup=False,
    params={
        "date": Param(
            default=pendulum.now("America/Los_Angeles").strftime("%Y-%m-%d, %H:%M:%S")
        )
    },
) as dag:
    PythonOperator(
        task_id="print_date",
        python_callable=print_param,
        op_kwargs={"date": "{{params.date}}"},
    )

  1. Scheduled run behavior - The above DAG runs every hour. Once a schedule run is completed, examine the log in print_date. Clear the task and examine the log in attempt Bring in more resolution to hivestats #2, the timestamp is now a different value
  2. Manually triggered behavior - Manually trigger the DAG. Once the run is completed, clear print_date task and examine the log in attempt Bring in more resolution to hivestats #2, the timestamp should be identical to the timestamp in attempt Improving the search functionality in the graph view #1

Operating System

Amazon Linux 2

Versions of Apache Airflow Providers

No response

Deployment

Amazon (AWS) MWAA

Deployment details

No response

Anything else?

No response

Are you willing to submit PR?

  • Yes I am willing to submit a PR!

Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions