From 9d7632bb5dd3beb5540ba49197d697a7e1e5987c Mon Sep 17 00:00:00 2001 From: Iaroslav Zeigerman Date: Thu, 19 Jun 2025 09:13:40 -0700 Subject: [PATCH] Fix: Fetch full environment object one a time to prevent loading all of them at once --- sqlmesh/core/plan/evaluator.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/sqlmesh/core/plan/evaluator.py b/sqlmesh/core/plan/evaluator.py index d1d9df8f28..d959fd27a4 100644 --- a/sqlmesh/core/plan/evaluator.py +++ b/sqlmesh/core/plan/evaluator.py @@ -400,7 +400,13 @@ def _restatement_intervals_across_all_environments( snapshots_to_restate: t.Dict[SnapshotId, t.Tuple[SnapshotTableInfo, Interval]] = {} - for env in self.state_sync.get_environments(): + for env_summary in self.state_sync.get_environments_summary(): + # Fetch the full environment object one at a time to avoid loading all environments into memory at once + env = self.state_sync.get_environment(env_summary.name) + if not env: + logger.warning("Environment %s not found", env_summary.name) + continue + keyed_snapshots = {s.name: s.table_info for s in env.snapshots} # We dont just restate matching snapshots, we also have to restate anything downstream of them