This is an automated email from the ASF dual-hosted git repository.
kaxilnaik pushed a commit to branch v3-0-test
in repository https://gitbox.apache.org/repos/asf/airflow.git
The following commit(s) were added to refs/heads/v3-0-test by this push:
new 78a981a9738 [v3-0-test] Exclude dag.fileloc from determining dag
version (#54477) (#54483)
78a981a9738 is described below
commit 78a981a97382ff9a4984a333182b4ea48f5a8aa2
Author: github-actions[bot]
<41898282+github-actions[bot]@users.noreply.github.com>
AuthorDate: Mon Aug 18 16:47:58 2025 +0100
[v3-0-test] Exclude dag.fileloc from determining dag version (#54477)
(#54483)
A combination of bundle path and dag.relative_fileloc more correctly
determines the right location of a dag and not dag.fileloc. This PR
excludes fileloc from determining the creation of a new dag version.
(cherry picked from commit 9efadf806cb29eef0793cc171932d74f0b611765)
Co-authored-by: Ephraim Anierobi <[email protected]>
---
airflow-core/src/airflow/models/serialized_dag.py | 8 ++++++-
.../tests/unit/models/test_serialized_dag.py | 28 ++++++++++++++++++++++
2 files changed, 35 insertions(+), 1 deletion(-)
diff --git a/airflow-core/src/airflow/models/serialized_dag.py
b/airflow-core/src/airflow/models/serialized_dag.py
index 71722b54ade..684cea84779 100644
--- a/airflow-core/src/airflow/models/serialized_dag.py
+++ b/airflow-core/src/airflow/models/serialized_dag.py
@@ -350,7 +350,13 @@ class SerializedDagModel(Base):
def hash(cls, dag_data):
"""Hash the data to get the dag_hash."""
dag_data = cls._sort_serialized_dag_dict(dag_data)
- data_json = json.dumps(dag_data, sort_keys=True).encode("utf-8")
+ data_ = dag_data.copy()
+ # Remove fileloc from the hash so changes to fileloc
+ # does not affect the hash. In 3.0+, a combination of
+ # bundle_path and relative fileloc more correctly determines the
+ # dag file location.
+ data_["dag"].pop("fileloc", None)
+ data_json = json.dumps(data_, sort_keys=True).encode("utf-8")
return md5(data_json).hexdigest()
@classmethod
diff --git a/airflow-core/tests/unit/models/test_serialized_dag.py
b/airflow-core/tests/unit/models/test_serialized_dag.py
index d30d71d0b02..f6277038dd9 100644
--- a/airflow-core/tests/unit/models/test_serialized_dag.py
+++ b/airflow-core/tests/unit/models/test_serialized_dag.py
@@ -522,3 +522,31 @@ class TestSerializedDagModel:
# There should now be two versions of the DAG
assert session.query(DagVersion).count() == 2
+
+ def test_hash_method_removes_fileloc_and_remains_consistent(self):
+ """Test that the hash method removes fileloc before hashing."""
+ test_data = {
+ "__version": 1,
+ "dag": {
+ "fileloc": "/path/to/dag.py",
+ "dag_id": "test_dag",
+ "tasks": {
+ "task1": {"task_id": "task1"},
+ },
+ },
+ }
+
+ hash_with_fileloc = SDM.hash(test_data)
+
+ # Modify only the top-level dag.fileloc path (simulating file location
changes)
+ test_data["dag"]["fileloc"] = "/different/path/to/dag.py"
+
+ # Get hash with different top-level fileloc (should be the same)
+ hash_with_different_fileloc = SDM.hash(test_data)
+
+ # Hashes should be identical since top-level dag.fileloc is removed
before hashing
+ assert hash_with_fileloc == hash_with_different_fileloc
+
+ # Verify that the original data still has fileloc (method shouldn't
modify original)
+ assert "fileloc" in test_data["dag"]
+ assert test_data["dag"]["fileloc"] == "/different/path/to/dag.py"