Copilot commented on code in PR #68336:
URL: https://github.com/apache/airflow/pull/68336#discussion_r3388336736
##########
airflow-core/tests/unit/models/test_serialized_dag.py:
##########
@@ -585,6 +585,63 @@ def
test_new_dag_version_created_when_bundle_name_changes_and_hash_unchanged(sel
# There should now be two versions of the DAG
assert session.scalar(select(func.count()).select_from(DagVersion)) ==
2
+ def test_bundle_version_refreshed_in_place_when_hash_unchanged(self,
dag_maker, session):
+ """When the bundle advances to a new version/commit but the DAG's
serialized
+ content is unchanged, ``write_dag`` must refresh the latest
DagVersion's
+ ``bundle_version`` in place (so tasks resolve the current commit)
without
+ creating a new DagVersion (which would inflate versions on every
commit).
+ """
+ with dag_maker("test_dag_bundle_version_refresh",
bundle_name="bundleA") as dag:
+ EmptyOperator(task_id="task1")
+ # Pin the version with task instances so the in-place "no TI" branch
is NOT taken.
+ dag_maker.create_dagrun(run_id="test_run")
+
+ did_write = SDM.write_dag(
+ LazyDeserializedDAG.from_dag(dag),
+ bundle_name="bundleA",
+ bundle_version="commit_A",
+ session=session,
+ )
+ assert did_write is True
+ assert session.scalar(select(func.count()).select_from(DagVersion)) ==
1
+ assert DagVersion.get_latest_version(dag.dag_id,
session=session).bundle_version == "commit_A"
+
+ # Same content, same bundle_name, but the bundle moved to a new commit.
+ did_write = SDM.write_dag(
+ LazyDeserializedDAG.from_dag(dag),
+ bundle_name="bundleA",
+ bundle_version="commit_B",
+ session=session,
+ )
+
+ # No new version was created, but the latest version's bundle pointer
advanced.
+ assert did_write is True
+ assert session.scalar(select(func.count()).select_from(DagVersion)) ==
1
+ assert DagVersion.get_latest_version(dag.dag_id,
session=session).bundle_version == "commit_B"
Review Comment:
The in-place refresh logic updates both `bundle_version` and `version_data`,
but this test only asserts the `bundle_version` change. Adding `version_data`
assertions would better protect the new behavior from regressions.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]