From 56fadc9365e43a9ada05990b926e2cc82351fa77 Mon Sep 17 00:00:00 2001 From: cnahed-kpler Date: Wed, 27 May 2026 08:04:07 +0200 Subject: [PATCH] Fix: load materializations before run janitor --- sqlmesh/core/context.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/sqlmesh/core/context.py b/sqlmesh/core/context.py index 4eb0d3b40b..0cd24c464e 100644 --- a/sqlmesh/core/context.py +++ b/sqlmesh/core/context.py @@ -784,6 +784,8 @@ def run( Returns: True if the run was successful, False otherwise. """ + self._load_materializations() + environment = environment or self.config.default_target_environment environment = Environment.sanitize_name(environment) if not skip_janitor and environment.lower() == c.PROD: @@ -796,7 +798,6 @@ def run( engine_type=self.snapshot_evaluator.adapter.dialect, state_sync_type=self.state_sync.state_type(), ) - self._load_materializations() env_check_attempts_num = max( 1, @@ -888,6 +889,7 @@ def _has_environment_changed() -> bool: @python_api_analytics def run_janitor(self, ignore_ttl: bool, force_delete: bool = False) -> bool: + self._load_materializations() success = False if self.console.start_cleanup(ignore_ttl): @@ -2884,6 +2886,8 @@ def _destroy(self) -> bool: self.state_sync.invalidate_environment(name=environment.name, protect_prod=False) self.console.log_success(f"Environment '{environment.name}' invalidated.") + self._load_materializations() + # Run janitor to clean up all objects self._run_janitor(ignore_ttl=True)