Skip to content

Fix DagRun.dag_versions after partial run_on_latest_version clear - #71459

Open
dgvj-work wants to merge 2 commits into
apache:mainfrom
dgvj-work:fix/dag-versions-partial-run-on-latest
Open

Fix DagRun.dag_versions after partial run_on_latest_version clear#71459
dgvj-work wants to merge 2 commits into
apache:mainfrom
dgvj-work:fix/dag-versions-partial-run-on-latest

Conversation

@dgvj-work

@dgvj-workdgvj-work commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Fix DagRun.dag_versions silently dropping older versions still in use after a partial run_on_latest_version clear.

For bundle-versioned runs the property previously returned only created_dag_version. Clearing a subset with run_on_latest_version=True bumps that pointer to latest while uncleared TaskInstances keep their older dag_version_id, so the Grid UI could show a single version chip while tasks were still executing under mixed versions.

Changes

  • Always derive DagRun.dag_versions from the run's TaskInstance / TaskInstanceHistory rows (same path as unpinned runs).
  • Update attach_dag_versions_to_runs to prefetch for bundle-versioned runs as well, so Grid/UI keeps the lightweight DISTINCT query path and still sees mixed versions.

closes: #71454

Testing

  • uv run --project airflow-core pytest airflow-core/tests/unit/models/test_dagrun.py::TestDagRun::test_dag_run_dag_versions_method airflow-core/tests/unit/models/test_dagrun.py::TestDagRun::test_dag_run_dag_versions_with_null_created_dag_version airflow-core/tests/unit/models/test_dagrun.py::TestDagRun::test_dag_run_dag_versions_after_partial_run_on_latest_version -q

Was generative AI tooling used to co-author this PR?
  • Yes (please specify the tool below)

Stop special-casing bundle-versioned runs through created_dag_version_id.
Always derive versions from the run's TaskInstance / history rows so mixed
versions after a partial clear are reported correctly.
Closesapache#71454
Signed-off-by: Digvijay <digvijay.vaghela@yahoo.com>
attach_dag_versions_to_runs previously skipped runs with bundle_version,
assuming dag_versions used created_dag_version. After removing that
shortcut, prefetch all runs so Grid/UI keeps the lightweight path and
still sees mixed TI versions.
Signed-off-by: Digvijay <digvijay.vaghela@yahoo.com>

@pierrejeambrunpierrejeambrun left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We also have #71425 to address the same issue.
Edit: #71425 isn't solving that issue.

@ephraimbuddy@dstandish wdyt?

This doesn't solve the contract problem mentioned in the other PR but can help sove the immediate reported issues with minimal effort. While we figure out the interface we want.

@pierrejeambrunpierrejeambrun left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

A few nits, looking good to me.

Comment on lines +1394 to +1396
Repro for apache/airflow#71454: clearing a subset with run_on_latest_version=True bumps
created_dag_version_id / bundle_version to latest while uncleared TIs stay on the old
version. The property must report both.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
Reproforapache/airflow#71454: clearing a subset with run_on_latest_version=True bumps
created_dag_version_id/bundle_versiontolatestwhileunclearedTIsstayontheold
version. Thepropertymustreportboth.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We do not specify issues number in tests.

assert {dv.id for dv in versions} == ti_version_ids
assert None not in versions

def test_dag_run_dag_versions_after_partial_run_on_latest_version(self, dag_maker, session):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Metion bundled version in the test name and docstring I guess

Comment on lines +535 to +537
# Always derive from actual TI/TIH versions. Do not special-case bundle-versioned
# runs via created_dag_version_id: clear(..., run_on_latest_version=True) can bump
# that pointer while leaving uncleared TIs on older versions (apache/airflow#71454).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
# Always derive from actual TI/TIH versions. Do not special-case bundle-versioned
# runs via created_dag_version_id: clear(..., run_on_latest_version=True) can bump
# that pointer while leaving uncleared TIs on older versions (apache/airflow#71454).
# Always derive from actual TI/TIH versions.

Sign up for freeto 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.

DagRun.dag_versions silently drops versions after a partial "run on latest version" clear

2 participants

@dgvj-work@pierrejeambrun