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 382a9618ed Fix hash caching in `ObjectStoragePath` (#37769)
382a9618ed is described below
commit 382a9618ed15403766ec7d1bcbe41ed955b3e60d
Author: Andrey Anshin <[email protected]>
AuthorDate: Wed Feb 28 17:05:58 2024 +0400
Fix hash caching in `ObjectStoragePath` (#37769)
---
airflow/io/path.py | 6 +++---
tests/io/test_path.py | 9 +++++++++
2 files changed, 12 insertions(+), 3 deletions(-)
diff --git a/airflow/io/path.py b/airflow/io/path.py
index d65d837e7e..bbe63be5e9 100644
--- a/airflow/io/path.py
+++ b/airflow/io/path.py
@@ -17,7 +17,6 @@
from __future__ import annotations
import contextlib
-import functools
import os
import shutil
import typing
@@ -152,9 +151,10 @@ class ObjectStoragePath(CloudPath):
return cls._from_parts(args_list, url=parsed_url, conn_id=conn_id,
**kwargs) # type: ignore
- @functools.lru_cache
def __hash__(self) -> int:
- return hash(str(self))
+ if not (_hash := getattr(self, "_hash", None)):
+ self._hash = _hash = hash(str(self))
+ return _hash
def __eq__(self, other: typing.Any) -> bool:
return self.samestore(other) and str(self) == str(other)
diff --git a/tests/io/test_path.py b/tests/io/test_path.py
index deb8d412cc..b631d2ba78 100644
--- a/tests/io/test_path.py
+++ b/tests/io/test_path.py
@@ -318,3 +318,12 @@ class TestFs:
o = ObjectStoragePath(i)
assert o.protocol == p
assert o.path == f
+
+ def test_hash(self):
+ file_uri_1 = f"file:///tmp/{str(uuid.uuid4())}"
+ file_uri_2 = f"file:///tmp/{str(uuid.uuid4())}"
+ s = set()
+ for _ in range(10):
+ s.add(ObjectStoragePath(file_uri_1))
+ s.add(ObjectStoragePath(file_uri_2))
+ assert len(s) == 2