Skip to content

Commit b207702

Browse files
committed
Fix: Don't fail because of an unrestorable change if the target model is forward-only (#3835)
1 parent c5b695c commit b207702

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

sqlmesh/core/plan/builder.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -641,6 +641,8 @@ def _ensure_no_forward_only_revert(self) -> None:
641641
for name, (candidate, promoted) in self._context_diff.modified_snapshots.items():
642642
if (
643643
candidate.snapshot_id not in self._context_diff.new_snapshots
644+
and candidate.is_model
645+
and not candidate.model.forward_only
644646
and promoted.is_forward_only
645647
and not promoted.is_paused
646648
and not candidate.reuses_previous_version

tests/core/test_integration.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2964,7 +2964,7 @@ def test_new_forward_only_model_concurrent_versions(init_and_plan_context: t.Cal
29642964
)
29652965
new_model_alt = load_sql_based_model(new_model_alt_expr)
29662966

2967-
# Add the second version of the model and apply it to dev_b.
2967+
# Add the second version of the model but don't apply it yet
29682968
context.upsert_model(new_model_alt)
29692969
snapshot_b = context.get_snapshot(new_model_alt.name)
29702970
plan_b = context.plan_builder("dev_b").build()
@@ -2977,8 +2977,6 @@ def test_new_forward_only_model_concurrent_versions(init_and_plan_context: t.Cal
29772977
assert snapshot_b.fingerprint != snapshot_a.fingerprint
29782978
assert snapshot_b.version == snapshot_a.version
29792979

2980-
context.apply(plan_b)
2981-
29822980
# Apply the 1st version to prod
29832981
context.upsert_model(new_model)
29842982
plan_prod_a = context.plan_builder("prod").build()
@@ -2992,10 +2990,20 @@ def test_new_forward_only_model_concurrent_versions(init_and_plan_context: t.Cal
29922990
df = context.fetchdf("SELECT * FROM memory.sushi.new_model")
29932991
assert df.to_dict() == {"ds": {0: "2023-01-07"}, "a": {0: 1}}
29942992

2993+
# Modify the 1st version in prod to trigger a forward-only change
2994+
new_model = add_projection_to_model(t.cast(SqlModel, new_model))
2995+
context.upsert_model(new_model)
2996+
context.plan("prod", auto_apply=True, no_prompts=True, skip_tests=True)
2997+
2998+
# Apply the 2nd version to dev_b.
2999+
# At this point the snapshot of the 2nd version has already been categorized but not
3000+
# persisted in the state. This means that when the snapshot of the 1st version was
3001+
# being unpaused during promotion to prod, the state of the 2nd version snapshot was not updated
3002+
context.apply(plan_b)
3003+
29953004
# Apply the 2nd version to prod
29963005
context.upsert_model(new_model_alt)
29973006
plan_prod_b = context.plan_builder("prod").build()
2998-
assert snapshot_b.snapshot_id in plan_prod_b.snapshots
29993007
assert (
30003008
plan_prod_b.snapshots[snapshot_b.snapshot_id].change_category
30013009
== SnapshotChangeCategory.BREAKING

0 commit comments

Comments
 (0)