Skip to content

Refresh bundle version in place when DAG serialization is unchanged#68336

Merged
ephraimbuddy merged 2 commits into
apache:mainfrom
astronomer:fix-stale-bundle-version-on-unchanged-dag
Jun 15, 2026
Merged

Refresh bundle version in place when DAG serialization is unchanged#68336
ephraimbuddy merged 2 commits into
apache:mainfrom
astronomer:fix-stale-bundle-version-on-unchanged-dag

Conversation

@ephraimbuddy

Copy link
Copy Markdown
Contributor

When a DAG bundle advances to a new version/commit but the DAG's serialized content is byte-identical, write_dag took the 'unchanged' fast path and left the latest DagVersion's bundle_version pinned to the old commit. Tasks resolve their code from ti.dag_version.bundle_version at run time, so new runs and reruns 'with the latest bundle version' executed an outdated commit.

Refresh the latest version's bundle_version/version_data (and dag code) in place instead. This does not create a new DagVersion, avoiding version inflation on every bundle commit, while keeping the recorded bundle pointer current.

closes: #67657

Copilot AI 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.

Pull request overview

This PR fixes an Airflow core correctness issue where SerializedDagModel.write_dag() took the “unchanged serialized DAG” fast path and left DagVersion.bundle_version (and version_data) pointing at an older bundle commit, causing task re-runs requested “with latest bundle version” to execute stale code.

Changes:

  • Refresh DagVersion.bundle_version/version_data in place when the DAG serialization hash is unchanged (and bundle name is unchanged), instead of skipping the write entirely.
  • Update DagCode source in the same in-place refresh path so stored DAG code stays aligned with the refreshed bundle pointer.
  • Add unit tests covering the in-place bundle version refresh and the true no-op case when bundle metadata is unchanged.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
airflow-core/src/airflow/models/serialized_dag.py Updates the “hash unchanged” fast path to refresh bundle metadata (and DAG code) in place rather than leaving a stale bundle pointer.
airflow-core/tests/unit/models/test_serialized_dag.py Adds regression tests ensuring bundle version refresh happens without creating new DagVersion rows and that identical bundle metadata remains a no-op.

Comment thread airflow-core/tests/unit/models/test_serialized_dag.py Outdated
@ephraimbuddy ephraimbuddy force-pushed the fix-stale-bundle-version-on-unchanged-dag branch from 3a2583f to 64abe52 Compare June 10, 2026 14:28
ephraimbuddy and others added 2 commits June 11, 2026 12:48
When a DAG bundle advances to a new version/commit but the DAG's
serialized content is byte-identical, write_dag took the 'unchanged'
fast path and left the latest DagVersion's bundle_version pinned to the
old commit. Tasks resolve their code from ti.dag_version.bundle_version
at run time, so new runs and reruns 'with the latest bundle version'
executed an outdated commit.

Refresh the latest version's bundle_version/version_data (and dag code)
in place instead. This does not create a new DagVersion, avoiding version
inflation on every bundle commit, while keeping the recorded bundle
pointer current.

closes: apache#67657
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@ephraimbuddy ephraimbuddy force-pushed the fix-stale-bundle-version-on-unchanged-dag branch from 64abe52 to e111b23 Compare June 11, 2026 11:48
@ephraimbuddy ephraimbuddy self-assigned this Jun 15, 2026
Comment thread airflow-core/src/airflow/models/serialized_dag.py
@ephraimbuddy ephraimbuddy requested a review from uranusjr June 15, 2026 11:09
@ephraimbuddy ephraimbuddy merged commit e09ad45 into apache:main Jun 15, 2026
77 checks passed
@ephraimbuddy ephraimbuddy deleted the fix-stale-bundle-version-on-unchanged-dag branch June 15, 2026 11:26
@vatsrahul1001 vatsrahul1001 added this to the Airflow 3.3.0 milestone Jun 15, 2026
pgagnon pushed a commit to pgagnon/airflow that referenced this pull request Jun 15, 2026
…pache#68336)

* Refresh bundle version in place when DAG serialization is unchanged

When a DAG bundle advances to a new version/commit but the DAG's
serialized content is byte-identical, write_dag took the 'unchanged'
fast path and left the latest DagVersion's bundle_version pinned to the
old commit. Tasks resolve their code from ti.dag_version.bundle_version
at run time, so new runs and reruns 'with the latest bundle version'
executed an outdated commit.

Refresh the latest version's bundle_version/version_data (and dag code)
in place instead. This does not create a new DagVersion, avoiding version
inflation on every bundle commit, while keeping the recorded bundle
pointer current.

closes: apache#67657

* Potential fix for pull request finding

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

---------

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
imrichardwu pushed a commit to imrichardwu/airflow that referenced this pull request Jun 16, 2026
…pache#68336)

* Refresh bundle version in place when DAG serialization is unchanged

When a DAG bundle advances to a new version/commit but the DAG's
serialized content is byte-identical, write_dag took the 'unchanged'
fast path and left the latest DagVersion's bundle_version pinned to the
old commit. Tasks resolve their code from ti.dag_version.bundle_version
at run time, so new runs and reruns 'with the latest bundle version'
executed an outdated commit.

Refresh the latest version's bundle_version/version_data (and dag code)
in place instead. This does not create a new DagVersion, avoiding version
inflation on every bundle commit, while keeping the recorded bundle
pointer current.

closes: apache#67657

* Potential fix for pull request finding

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

---------

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
dingo4dev pushed a commit to dingo4dev/airflow that referenced this pull request Jun 16, 2026
…pache#68336)

* Refresh bundle version in place when DAG serialization is unchanged

When a DAG bundle advances to a new version/commit but the DAG's
serialized content is byte-identical, write_dag took the 'unchanged'
fast path and left the latest DagVersion's bundle_version pinned to the
old commit. Tasks resolve their code from ti.dag_version.bundle_version
at run time, so new runs and reruns 'with the latest bundle version'
executed an outdated commit.

Refresh the latest version's bundle_version/version_data (and dag code)
in place instead. This does not create a new DagVersion, avoiding version
inflation on every bundle commit, while keeping the recorded bundle
pointer current.

closes: apache#67657

* Potential fix for pull request finding

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

---------

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
RulerChen pushed a commit to RulerChen/airflow that referenced this pull request Jun 16, 2026
…pache#68336)

* Refresh bundle version in place when DAG serialization is unchanged

When a DAG bundle advances to a new version/commit but the DAG's
serialized content is byte-identical, write_dag took the 'unchanged'
fast path and left the latest DagVersion's bundle_version pinned to the
old commit. Tasks resolve their code from ti.dag_version.bundle_version
at run time, so new runs and reruns 'with the latest bundle version'
executed an outdated commit.

Refresh the latest version's bundle_version/version_data (and dag code)
in place instead. This does not create a new DagVersion, avoiding version
inflation on every bundle commit, while keeping the recorded bundle
pointer current.

closes: apache#67657

* Potential fix for pull request finding

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

---------

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Old DAG version used even when selecting Run with latest bundle version on task instance "clear"

4 participants