Skip to content

AirflowRuntimeVaryingValueChecker misses runtime-varying values in tasks after nested non-DAG with-statements #68796

Closed

Description

@kalluripradeep

Under which category would you file this issue?

Airflow Core

Apache Airflow version

main

What happened and how to reproduce it?

When a non-DAG with-statement (e.g. with open(...) as f) is nested inside a DAG with-block, any tasks constructed AFTER that nested with — but still inside the DAG block — are silently missed by the DAG version inflation checker. datetime.now(), random(), uuid4() etc. in those tasks are never flagged.

To reproduce:

from airflow import DAG
from datetime import datetime
from airflow.operators.bash import BashOperator

with DAG('my_dag') as dag:
    with open('file.txt') as f:   # non-DAG with-statement
        data = f.read()
    # datetime.now() here is NOT flagged — but it should be
    t1 = BashOperator(task_id='t', bash_command=str(datetime.now()))

Root cause: visit_With() in dag_version_inflation_checker.py calls exit_dag_context() unconditionally at the end of every with-statement, even non-DAG ones. This resets is_in_dag_context=False, blinding the checker to subsequent tasks.

What you think should happen instead?

The BashOperator using datetime.now() should be flagged as a runtime-varying value causing DAG version inflation, because it is still inside the DAG with-block.

Operating System

Any

Deployment

None

Apache Airflow Provider(s)

No response

Versions of Apache Airflow Providers

No response

Official Helm Chart version

Not Applicable

Kubernetes Version

No response

Helm Chart configuration

No response

Docker Image customizations

No response

Anything else?

No response

Are you willing to submit PR?

  • Yes I am willing to submit a PR!

Code of Conduct

Activity

  1. added
    kind:bug
    needs-triage
    on Jun 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:corekind:bugneeds-triage

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions