Skip to content

Detect Dag subclasses in the Dag version inflation check - #72861

Merged
jedcunningham merged 1 commit into
apache:mainfrom
astronomer:dag-detector-by-name
Sep 10, 2026
Merged

jedcunningham merged 1 commit into
apache:mainfrom
astronomer:dag-detector-by-name

Conversation

@jedcunningham

Copy link
Copy Markdown
Member

The Dag version inflation check only spotted a Dag constructor when the callable resolved
through a from-import of airflow's DAG or dag. A Dag built from a subclass, or reached
through an aliased module import, produced no warnings at all — and since task detection keys
off the same predicate, neither did any task inside its with block.

Detection now uses the callable's name as well as the import table. The check runs before the
Dag file is imported, so there is no object to test — the name and the file's own imports are
the only evidence available.

Newly caught, both silent before:

# a Dag subclass from a shared library — the task inside it is flagged too
with TeamDAG():
    BashOperator(task_id=f"t_{datetime.now()}")

# a module reached through an aliased import: import airflow.sdk as sdk
sdk.DAG(start_date=datetime.now())

Three consequences of the heuristic, worth a reviewer's attention:

  • A non-Dag named *Dag assigned to a variable is treated as a Dag, so real warnings on later
    uses of that variable are lost:

    stamp = StampDag(datetime.now())        # flagged as a Dag constructor
    with DAG():
        BashOperator(task_id=f"a_{stamp}")  # warned before this change, silent now

    Tracking the assignment anyway would restore that warning, at the cost of the common path:

    dag = DAG(start_date=datetime.now())  # the real problem, already warned
    BashOperator(dag=dag)                 # would start warning, though nothing is wrong

    Both are a varying-valued call detected as a Dag constructor and assigned to a name, so
    nothing downstream separates them — it is a choice of which one to get wrong. Assigning a Dag
    and passing dag=dag to its tasks is everyday Airflow; naming a non-Dag *Dag is not. So
    tracking would trade a rare miss for a routine false positive, on the very case the check
    exists to catch.

  • The suffix is case-sensitive, so create_DAG() matches where create_dag() does not. A name
    cannot tell a Dag subclass from a factory function.

  • At error level a false positive marks the Dag stale, so it stops scheduling rather than
    merely failing to parse. The default is warning, so this is opt-in.


Was generative AI tooling used to co-author this PR?
  • Yes — Claude Code (Opus 5)

Generated-by: Claude Code (Opus 5)

The check only recognized a Dag constructor when the callable resolved
through a from-import of airflow's DAG or dag. A Dag built from a
subclass, or reached through an aliased module import, produced no
warnings at all — and because task detection keys off the same
predicate, neither did any task inside its with-block.

The Dag file is not imported yet when the check runs, so there is no
object to test — only names and the file's own imports. The cost of
leaning on names is an occasional false positive on something merely
named like a Dag.

@amoghrajesh amoghrajesh left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with one qn

@jedcunningham
jedcunningham merged commit 1e2ad80 into apache:main Sep 10, 2026
155 checks passed
@jedcunningham
jedcunningham deleted the dag-detector-by-name branch September 10, 2026 16:43
@github-actions

Copy link
Copy Markdown
Contributor

Backport successfully created: v3-3-test

Note: As of Merging PRs targeted for Airflow 3.X
the committer who merges the PR is responsible for backporting the PRs that are bug fixes (generally speaking) to the maintenance branches.

In matter of doubt please ask in #release-management Slack channel.

Status Branch Result
✅ v3-3-test PR Link

aws-airflow-bot pushed a commit to aws-mwaa/upstream-to-airflow that referenced this pull request Sep 10, 2026
…pache#72861)

The check only recognized a Dag constructor when the callable resolved
through a from-import of airflow's DAG or dag. A Dag built from a
subclass, or reached through an aliased module import, produced no
warnings at all — and because task detection keys off the same
predicate, neither did any task inside its with-block.

The Dag file is not imported yet when the check runs, so there is no
object to test — only names and the file's own imports. The cost of
leaning on names is an occasional false positive on something merely
named like a Dag.
(cherry picked from commit 1e2ad80)

Co-authored-by: Jed Cunningham <[email protected]>
vatsrahul1001 added a commit that referenced this pull request Sep 11, 2026
…72861) (#72898)

* [v3-3-test] Detect Dag subclasses in the Dag version inflation check (#72861)

The check only recognized a Dag constructor when the callable resolved
through a from-import of airflow's DAG or dag. A Dag built from a
subclass, or reached through an aliased module import, produced no
warnings at all — and because task detection keys off the same
predicate, neither did any task inside its with-block.

The Dag file is not imported yet when the check runs, so there is no
object to test — only names and the file's own imports. The cost of
leaning on names is an occasional false positive on something merely
named like a Dag.
(cherry picked from commit 1e2ad80)

Co-authored-by: Jed Cunningham <[email protected]>

* Add missing dedent import to fix the version inflation checker tests

---------

Co-authored-by: Jed Cunningham <[email protected]>
Co-authored-by: Rahul Vats <[email protected]>
Co-authored-by: Rahul Vats <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants