Tidy DagVersion/DagCode metadata helpers#68627
Open
ephraimbuddy wants to merge 2 commits into
Open
Conversation
ephraimbuddy
commented
Jun 16, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
This PR tidies up Airflow’s DAG version/code metadata helpers by fixing edge-case filtering behavior, simplifying bundle URL resolution logic, and ensuring DagCode.update_source_code() keeps related metadata consistent.
Changes:
- Fix
DagVersion.get_version()soversion_number=0is treated as a real filter (instead of falling back to “latest”). - Simplify
DagVersion.bundle_urlby relying onDagBundleModel.render_url()when a bundle row is present and only using the deprecated manager path when no bundle row exists. - Update
DagCode.update_source_code()to refreshfilelocwhen the source is refreshed, and add regression coverage.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| airflow-core/src/airflow/models/dag_version.py | Fixes get_version zero-filter behavior; refines bundle_url selection logic. |
| airflow-core/src/airflow/models/dagcode.py | Updates update_source_code to keep fileloc aligned when refreshing stored source. |
| airflow-core/tests/unit/models/test_dag_version.py | Adds regression test ensuring version_number=0 filters rather than returning latest. |
| airflow-core/tests/unit/models/test_dagcode.py | Adds regression test verifying update_source_code refreshes stale fileloc on update path. |
phanikumv
reviewed
Jun 17, 2026
phanikumv
left a comment
Contributor
There was a problem hiding this comment.
CI is red on all four core DB jobs because of the bundle_url guard removal, a
test that was dependent on this logic needs fixing
Suggested replacement for airflow-core/tests/unit/api_fastapi/core_api/routes/public/test_dag_versions.py here
@pytest.mark.usefixtures("make_dag_with_multiple_versions")
@mock.patch("airflow.models.dagbundle.DagBundleModel.render_url", return_value=None)
def test_get_dag_version_with_unconfigured_bundle(self, mock_render_url, test_client):
"""A bundle row with no URL template yields an empty bundle_url."""
response = test_client.get("/dags/dag_with_multiple_versions/dagVersions/1")
assert response.status_code == 200
assert not response.json()["bundle_url"]
- get_version: use 'if version_number is not None' so version_number=0 filters (and 404s) instead of falling through to the latest version. - bundle_url: drop the dead hasattr(self.bundle, 'signed_url_template') guard (always true on the ORM model). Behavior is unchanged: a loaded bundle uses render_url(), and the deprecated manager lookup is used only when there is no bundle row -- not on every call for bundles without a URL template. - DagCode.update_source_code: refresh fileloc alongside the source, and drop the redundant session.merge() on the already-session-attached row.
ephraimbuddy
force-pushed
the
dag-version-metadata-hygiene
branch
from
July 24, 2026 06:58
cba2a7c to
3a268fc
Compare
ephraimbuddy
force-pushed
the
dag-version-metadata-hygiene
branch
from
July 24, 2026 07:27
8e93a28 to
a597794
Compare
phanikumv
reviewed
Jul 24, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Was generative AI tooling used to co-author this PR?
claude opus 4.8