Skip to content

Commit 7b4157d

Browse files
authored
Fix: Don't fail because of an unrestorable change if the target model is forward-only (#3835)
1 parent 09217d1 commit 7b4157d

2 files changed

Lines changed: 14 additions & 4 deletions

File tree

sqlmesh/core/plan/builder.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -640,6 +640,8 @@ def _ensure_no_forward_only_revert(self) -> None:
640640
for name, (candidate, promoted) in self._context_diff.modified_snapshots.items():
641641
if (
642642
candidate.snapshot_id not in self._context_diff.new_snapshots
643+
and candidate.is_model
644+
and not candidate.model.forward_only
643645
and promoted.is_forward_only
644646
and not promoted.is_paused
645647
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
@@ -2980,7 +2980,7 @@ def test_new_forward_only_model_concurrent_versions(init_and_plan_context: t.Cal
29802980
)
29812981
new_model_alt = load_sql_based_model(new_model_alt_expr)
29822982

2983-
# Add the second version of the model and apply it to dev_b.
2983+
# Add the second version of the model but don't apply it yet
29842984
context.upsert_model(new_model_alt)
29852985
snapshot_b = context.get_snapshot(new_model_alt.name)
29862986
plan_b = context.plan_builder("dev_b").build()
@@ -2993,8 +2993,6 @@ def test_new_forward_only_model_concurrent_versions(init_and_plan_context: t.Cal
29932993
assert snapshot_b.fingerprint != snapshot_a.fingerprint
29942994
assert snapshot_b.version == snapshot_a.version
29952995

2996-
context.apply(plan_b)
2997-
29982996
# Apply the 1st version to prod
29992997
context.upsert_model(new_model)
30002998
plan_prod_a = context.plan_builder("prod").build()
@@ -3008,10 +3006,20 @@ def test_new_forward_only_model_concurrent_versions(init_and_plan_context: t.Cal
30083006
df = context.fetchdf("SELECT * FROM memory.sushi.new_model")
30093007
assert df.to_dict() == {"ds": {0: "2023-01-07"}, "a": {0: 1}}
30103008

3009+
# Modify the 1st version in prod to trigger a forward-only change
3010+
new_model = add_projection_to_model(t.cast(SqlModel, new_model))
3011+
context.upsert_model(new_model)
3012+
context.plan("prod", auto_apply=True, no_prompts=True, skip_tests=True)
3013+
3014+
# Apply the 2nd version to dev_b.
3015+
# At this point the snapshot of the 2nd version has already been categorized but not
3016+
# persisted in the state. This means that when the snapshot of the 1st version was
3017+
# being unpaused during promotion to prod, the state of the 2nd version snapshot was not updated
3018+
context.apply(plan_b)
3019+
30113020
# Apply the 2nd version to prod
30123021
context.upsert_model(new_model_alt)
30133022
plan_prod_b = context.plan_builder("prod").build()
3014-
assert snapshot_b.snapshot_id in plan_prod_b.snapshots
30153023
assert (
30163024
plan_prod_b.snapshots[snapshot_b.snapshot_id].change_category
30173025
== SnapshotChangeCategory.BREAKING

0 commit comments

Comments
 (0)