Skip to content

Commit

Permalink
Fix hash caching in ObjectStoragePath (#37769)
Browse files Browse the repository at this point in the history
  • Loading branch information
Taragolis authored Feb 28, 2024
1 parent bee0a7b commit 382a961
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
6 changes: 3 additions & 3 deletions airflow/io/path.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
from __future__ import annotations

import contextlib
import functools
import os
import shutil
import typing
Expand Down Expand Up @@ -152,9 +151,10 @@ def __new__(

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)
Expand Down
9 changes: 9 additions & 0 deletions tests/io/test_path.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,3 +318,12 @@ def test_dataset(self):
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

0 comments on commit 382a961

Please sign in to comment.