diff --git a/sqlmesh/core/context.py b/sqlmesh/core/context.py index d736c7244e..e8ab1954ec 100644 --- a/sqlmesh/core/context.py +++ b/sqlmesh/core/context.py @@ -781,6 +781,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: @@ -793,7 +795,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, @@ -885,6 +886,8 @@ def _has_environment_changed() -> bool: @python_api_analytics def run_janitor(self, ignore_ttl: bool) -> bool: + self._load_materializations() + success = False if self.console.start_cleanup(ignore_ttl): @@ -2873,6 +2876,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)