This is an automated email from the ASF dual-hosted git repository.

potiuk pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git


The following commit(s) were added to refs/heads/main by this push:
     new a42b88b59a1 fix(task-sdk): make Asset objects hashable (#60562)
a42b88b59a1 is described below

commit a42b88b59a1ab6ef5777259185df83df9304e8c6
Author: Sangbong Lee <[email protected]>
AuthorDate: Fri Jan 23 08:27:38 2026 +0900

    fix(task-sdk): make Asset objects hashable (#60562)
---
 task-sdk/src/airflow/sdk/definitions/asset/__init__.py |  3 ++-
 task-sdk/tests/task_sdk/definitions/test_asset.py      | 13 +++++++++++++
 2 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/task-sdk/src/airflow/sdk/definitions/asset/__init__.py 
b/task-sdk/src/airflow/sdk/definitions/asset/__init__.py
index 29eabafaf04..51f1b14e3b0 100644
--- a/task-sdk/src/airflow/sdk/definitions/asset/__init__.py
+++ b/task-sdk/src/airflow/sdk/definitions/asset/__init__.py
@@ -17,6 +17,7 @@
 
 from __future__ import annotations
 
+import json
 import logging
 import operator
 import os
@@ -379,7 +380,7 @@ class Asset(os.PathLike, BaseAsset):
 
     def __hash__(self):
         f = attrs.filters.include(*attrs.fields_dict(Asset))
-        return hash(attrs.asdict(self, filter=f))
+        return hash(json.dumps(attrs.asdict(self, filter=f), sort_keys=True))
 
     @property
     def normalized_uri(self) -> str | None:
diff --git a/task-sdk/tests/task_sdk/definitions/test_asset.py 
b/task-sdk/tests/task_sdk/definitions/test_asset.py
index f7e4502e379..cb95db92449 100644
--- a/task-sdk/tests/task_sdk/definitions/test_asset.py
+++ b/task-sdk/tests/task_sdk/definitions/test_asset.py
@@ -192,6 +192,19 @@ def test_not_equal_when_different_uri():
     assert asset1 != asset2
 
 
+def test_hash_for_same_uri():
+    asset1 = Asset(uri="s3://example/asset")
+    asset2 = Asset(uri="s3://example/asset")
+
+    assert hash(asset1) == hash(asset2)
+
+
+def test_hash_for_different_uri():
+    asset1 = Asset(uri="s3://bucket1/data1")
+    asset2 = Asset(uri="s3://bucket2/data2")
+    assert hash(asset1) != hash(asset2)
+
+
 asset1 = Asset(uri="s3://bucket1/data1", name="asset-1")
 asset2 = Asset(uri="s3://bucket2/data2", name="asset-2")
 asset3 = Asset(uri="s3://bucket3/data3", name="asset-3")

Reply via email to