From e769825e0b46ac564219a145bd242f84cef904ac Mon Sep 17 00:00:00 2001 From: vaggelisd Date: Thu, 7 Aug 2025 12:17:16 +0300 Subject: [PATCH] Fix: Do not initialize a state sync for sqlmesh clean --- sqlmesh/core/context.py | 4 ++-- tests/core/test_context.py | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/sqlmesh/core/context.py b/sqlmesh/core/context.py index 18df3a01fd..c0d9b21ff8 100644 --- a/sqlmesh/core/context.py +++ b/sqlmesh/core/context.py @@ -2537,8 +2537,8 @@ def clear_caches(self) -> None: if self.cache_dir.exists(): rmtree(self.cache_dir) - if isinstance(self.state_sync, CachingStateSync): - self.state_sync.clear_cache() + if isinstance(self._state_sync, CachingStateSync): + self._state_sync.clear_cache() def export_state( self, diff --git a/tests/core/test_context.py b/tests/core/test_context.py index 0f14fd4a8b..e0567e8168 100644 --- a/tests/core/test_context.py +++ b/tests/core/test_context.py @@ -647,6 +647,9 @@ def test_clear_caches(tmp_path: pathlib.Path): assert not cache_dir.exists() assert models_dir.exists() + # Ensure that we don't initialize a CachingStateSync only to clear its (empty) caches + assert context._state_sync is None + # Test clearing caches when cache directory doesn't exist # This should not raise an exception context.clear_caches()