Skip to content

Commit c5b695c

Browse files
committed
Fix: Only promote all snapshots if the target environment expired (#3797)
1 parent 3b97096 commit c5b695c

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

sqlmesh/core/state_sync/engine_adapter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ def promote(
332332
if (
333333
existing_environment
334334
and existing_environment.finalized_ts
335-
and not existing_environment.expiration_ts
335+
and not existing_environment.expired
336336
):
337337
# Only promote new snapshots.
338338
added_table_infos -= set(existing_environment.promoted_snapshots)

tests/core/test_state_sync.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -880,14 +880,26 @@ def test_promote_environment_expired(state_sync: EngineAdapterStateSync, make_sn
880880
end_at="2022-01-01",
881881
plan_id="new_plan_id",
882882
previous_plan_id=None, # No previous plan ID since it's technically a new environment
883+
expiration_ts=now_timestamp() + 3600,
883884
)
885+
assert new_environment.expiration_ts
884886

885887
# This call shouldn't fail.
886888
promotion_result = state_sync.promote(new_environment)
887889
assert promotion_result.added == [snapshot.table_info]
888890
assert promotion_result.removed == []
889891
assert promotion_result.removed_environment_naming_info is None
890892

893+
state_sync.finalize(new_environment)
894+
895+
new_environment.previous_plan_id = new_environment.plan_id
896+
new_environment.plan_id = "another_plan_id"
897+
promotion_result = state_sync.promote(new_environment)
898+
# Should be empty since the environment is no longer expired and nothing has changed
899+
assert promotion_result.added == []
900+
assert promotion_result.removed == []
901+
assert promotion_result.removed_environment_naming_info is None
902+
891903

892904
def test_promote_snapshots_no_gaps(state_sync: EngineAdapterStateSync, make_snapshot: t.Callable):
893905
model = SqlModel(

0 commit comments

Comments
 (0)