Skip to content

Commit 6be2b57

Browse files
authored
Fix: Correctly recreate views for snapshots categorized as indirect non-breaking (#1285)
1 parent df0903a commit 6be2b57

File tree

5 files changed

+16
-7
lines changed

5 files changed

+16
-7
lines changed

sqlmesh/core/plan/definition.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,7 @@ def _add_restatements(self, restate_models: t.Iterable[str]) -> None:
448448

449449
snapshots = self.context_diff.snapshots
450450
downstream = [
451-
d for d in downstream if snapshots[d].is_materialized and not snapshots[d].is_seed
451+
d for d in downstream if not snapshots[d].is_symbolic and not snapshots[d].is_seed
452452
]
453453

454454
if not self.is_dev:

sqlmesh/core/scheduler.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ def run(
209209
else:
210210
environment_naming_info = environment
211211

212-
is_dev = environment != c.PROD
212+
is_dev = environment_naming_info.name != c.PROD
213213
execution_time = execution_time or now()
214214
batches = self.batches(
215215
start,

sqlmesh/core/snapshot/evaluator.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,10 @@ def _create_snapshot(
419419
def _migrate_snapshot(
420420
self, snapshot: Snapshot, snapshots: t.Dict[SnapshotId, Snapshot]
421421
) -> None:
422-
if snapshot.change_category != SnapshotChangeCategory.FORWARD_ONLY:
422+
if not snapshot.is_paused or snapshot.change_category not in (
423+
SnapshotChangeCategory.FORWARD_ONLY,
424+
SnapshotChangeCategory.INDIRECT_NON_BREAKING,
425+
):
423426
return
424427

425428
parent_snapshots_by_name = {

tests/core/test_plan.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ def test_restate_models(sushi_context_pre_scheduling: Context):
145145
plan = sushi_context_pre_scheduling.plan(
146146
restate_models=["sushi.waiter_revenue_by_day"], no_prompts=True
147147
)
148-
assert plan.restatements == {"sushi.waiter_revenue_by_day"}
148+
assert plan.restatements == {"sushi.waiter_revenue_by_day", "sushi.top_waiters"}
149149
assert plan.requires_backfill
150150

151151
with pytest.raises(PlanError, match=r"Cannot restate from 'unknown_model'.*"):
@@ -157,7 +157,7 @@ def test_restate_model_with_merge_strategy(make_snapshot, mocker: MockerFixture)
157157
SqlModel(
158158
name="a",
159159
query=parse_one("select 1, key"),
160-
kind="VIEW",
160+
kind="EMBEDDED",
161161
)
162162
)
163163

tests/core/test_snapshot_evaluator.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,13 @@ def columns(table_name: t.Union[str, exp.Table]) -> t.Dict[str, exp.DataType]:
427427
)
428428

429429

430-
def test_migrate_view(mocker: MockerFixture, make_snapshot):
430+
@pytest.mark.parametrize(
431+
"change_category",
432+
[SnapshotChangeCategory.FORWARD_ONLY, SnapshotChangeCategory.INDIRECT_NON_BREAKING],
433+
)
434+
def test_migrate_view(
435+
mocker: MockerFixture, make_snapshot, change_category: SnapshotChangeCategory
436+
):
431437
connection_mock = mocker.NonCallableMock()
432438
cursor_mock = mocker.Mock()
433439
connection_mock.cursor.return_value = cursor_mock
@@ -442,7 +448,7 @@ def test_migrate_view(mocker: MockerFixture, make_snapshot):
442448
query=parse_one("SELECT c, a FROM tbl"),
443449
)
444450
snapshot = make_snapshot(model, version="1")
445-
snapshot.change_category = SnapshotChangeCategory.FORWARD_ONLY
451+
snapshot.change_category = change_category
446452

447453
evaluator.migrate([snapshot], {})
448454

0 commit comments

Comments
 (0)