Skip to content

Commit 4b478c4

Browse files
Fix: Don't fail when cache directories are already removed when clearing (#4758)
1 parent a9478a5 commit 4b478c4

2 files changed

Lines changed: 8 additions & 1 deletion

File tree

sqlmesh/core/context.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2438,7 +2438,9 @@ def table_name(
24382438

24392439
def clear_caches(self) -> None:
24402440
for path in self.configs:
2441-
rmtree(path / c.CACHE)
2441+
cache_path = path / c.CACHE
2442+
if cache_path.exists():
2443+
rmtree(cache_path)
24422444
if isinstance(self.state_sync, CachingStateSync):
24432445
self.state_sync.clear_cache()
24442446

tests/core/test_context.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -640,6 +640,11 @@ def test_clear_caches(tmp_path: pathlib.Path):
640640
assert not cache_dir.exists()
641641
assert models_dir.exists()
642642

643+
# Test clearing caches when cache directory doesn't exist
644+
# This should not raise an exception
645+
context.clear_caches()
646+
assert not cache_dir.exists()
647+
643648

644649
def test_ignore_files(mocker: MockerFixture, tmp_path: pathlib.Path):
645650
mocker.patch.object(

0 commit comments

Comments
 (0)