Skip to content

Commit 241774c

Browse files
committed
fix: load materializations before destroy snapshot reads
Signed-off-by: lafirm <136463254+lafirm@users.noreply.github.com>
1 parent 8a7edf8 commit 241774c

2 files changed

Lines changed: 5 additions & 4 deletions

File tree

‎sqlmesh/core/context.py‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1019,6 +1019,10 @@ def run_janitor(
10191019

10201020
@python_api_analytics
10211021
def destroy(self) -> bool:
1022+
# Load first so snapshot unpickling cannot import a custom-kind module that this load then reimports.
1023+
# If loading fails, abort before invalidating any environments.
1024+
self._load_materializations()
1025+
10221026
success = False
10231027

10241028
# Collect resources to be deleted
@@ -3158,9 +3162,6 @@ def _context_diff(
31583162
)
31593163

31603164
def _destroy(self) -> bool:
3161-
# Load materializations before any state writes so a failure aborts destroy without invalidating environments
3162-
self._load_materializations()
3163-
31643165
# Invalidate all environments, including prod
31653166
for environment in self.state_reader.get_environments():
31663167
self.state_sync.invalidate_environment(name=environment.name, protect_prod=False)

‎tests/core/integration/test_aux_commands.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ def test_destroy_fails_before_invalidating_environments_on_materialization_error
125125
context._materializations_loaded = False
126126

127127
with pytest.raises(SQLMeshError, match="broken materialization"):
128-
context._destroy()
128+
context.destroy()
129129

130130
assert context.state_reader.get_environment("prod").expiration_ts is None
131131

0 commit comments

Comments
 (0)