File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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 )
Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments