Skip to content

Commit 789e3f1

Browse files
authored
fix: remove write race conditions in cache operations (#2592)
1 parent bbc8bda commit 789e3f1

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

sqlmesh/utils/cache.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def __init__(
6565
# delete all old cache files
6666
for file in self._path.glob("*"):
6767
if not file.stem.startswith(self._cache_version) or file.stat().st_mtime < threshold:
68-
file.unlink()
68+
file.unlink(missing_ok=True)
6969

7070
def get_or_load(self, name: str, entry_id: str = "", *, loader: t.Callable[[], T]) -> T:
7171
"""Returns an existing cached entry or loads and caches a new one.
@@ -114,8 +114,7 @@ def put(self, name: str, entry_id: str = "", *, value: T) -> None:
114114
entry_id: The unique entry identifier. Used for cache invalidation.
115115
value: The value to store in the cache.
116116
"""
117-
if not self._path.exists():
118-
self._path.mkdir(parents=True)
117+
self._path.mkdir(parents=True, exist_ok=True)
119118
if not self._path.is_dir():
120119
raise SQLMeshError(f"Cache path '{self._path}' is not a directory.")
121120

0 commit comments

Comments
 (0)