Skip to content

Fix DagVersion.bundle_version not refreshed when only the bundle SHA changes#67545

Open
avolant wants to merge 4 commits into
apache:mainfrom
avolant:arthur.volant/fix-serialized-dag-bundle-version-check
Open

Fix DagVersion.bundle_version not refreshed when only the bundle SHA changes#67545
avolant wants to merge 4 commits into
apache:mainfrom
avolant:arthur.volant/fix-serialized-dag-bundle-version-check

Conversation

@avolant
Copy link
Copy Markdown
Contributor

@avolant avolant commented May 26, 2026

Summary

SerializedDagModel.write_dag short-circuits when the DAG hash and bundle name are unchanged, returning before persisting the new bundle_version. As a result, redeploying a bundle (new commit / archive) where a given DAG file is byte-identical leaves the existing DagVersion.bundle_version row pointing at the previous commit, even though DagFileProcessorManager._bundle_versions[bundle] already reflects the new commit.

Downstream callers that resolve "which bundle commit produced this DAG?" — for example the DAG source endpoint and task-instance/version history views — then return stale bundle artifacts (sibling files such as job definitions are served from the previous commit), which is surprising for users who redeploy a bundle expecting the new code to take effect.

Fix

Extend the short-circuit predicate with dag_version.bundle_version == bundle_version. If a bundle SHA change is observed for an otherwise-unchanged DAG, a new DagVersion row is created — mirroring the existing behaviour when bundle_name changes (covered by test_new_dag_version_created_when_bundle_name_changes_and_hash_unchanged).

The fix is safe for None bundle versions: both sides are None for non-versioned bundles (e.g. LocalDagBundle), so the new term is a no-op there.

Reproduction

With a versioned LocalDagBundle-style bundle (get_current_version() returning the commit SHA) and min_file_process_interval = 0 so the dag-processor re-queues the DAG on every refresh:

  1. Deploy bundle at SHA v1, parse — DagVersion.bundle_version = v1.
  2. Deploy a new bundle at SHA v2 where the DAG .py is byte-identical (only sibling files change). _bundle_versions[<bundle>] = v2, but write_dag returns False at the short-circuit and DagVersion.bundle_version stays at v1.

With this patch, step 2 creates a new DagVersion with bundle_version = v2.

Test

Added test_new_dag_version_created_when_bundle_version_changes_and_hash_unchanged next to the analogous bundle_name test in airflow-core/tests/unit/models/test_serialized_dag.py.


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

When `SerializedDagModel.write_dag` is called for an unchanged DAG file
that ships in a new bundle commit, the short-circuit at the top of
`write_dag` returns False before updating the existing `DagVersion`'s
`bundle_version`. The condition only checks `dag_hash` and
`bundle_name`, so a bundle redeploy with byte-identical DAG code never
refreshes the `bundle_version` column, even though the bundle
manager's `_bundle_versions` map already points at the new commit.

Downstream consumers (e.g. the DAG source endpoint, task instance
history, anything that resolves "which bundle commit ran this DAG?")
then resolve to a stale commit and serve outdated job code from
sibling files in the bundle.

Add `dag_version.bundle_version == bundle_version` to the
short-circuit so a bundle SHA change forces a new `DagVersion` row to
be created, mirroring the existing behaviour for `bundle_name`
changes.

Includes a regression test alongside the existing
`test_new_dag_version_created_when_bundle_name_changes_and_hash_unchanged`.

Signed-off-by: avolant <arthur.volant@datadoghq.com>
Signed-off-by: avolant <arthur.volant@datadoghq.com>
Comment thread airflow-core/newsfragments/67545.bugfix.rst Outdated
Signed-off-by: avolant <arthur.volant@datadoghq.com>
@avolant avolant requested a review from Pedrinhonitz May 26, 2026 11:14
@avolant
Copy link
Copy Markdown
Contributor Author

avolant commented May 27, 2026

Manually patched our deployment with my commit, and has been working for the past 48hours in production

@potiuk
Copy link
Copy Markdown
Member

potiuk commented May 28, 2026

@avolant A few things need addressing before review — see our Pull Request quality criteria.

  • Unit tests. See docs.
  • Other failing CI checks. See docs.

No rush.


Note: This comment was drafted by an AI-assisted triage tool and may contain mistakes. Once you have addressed the points above, an Apache Airflow maintainer — a real person — will take the next look at your PR. We use this two-stage triage process so that our maintainers' limited time is spent where it matters most: the conversation with you.

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.

3 participants