Skip to content

Commit 06e2541

Browse files
committed
fix manual categorization for the model kind change
1 parent dfa0e35 commit 06e2541

File tree

2 files changed

+49
-11
lines changed

2 files changed

+49
-11
lines changed

sqlmesh/core/plan/builder.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -586,7 +586,12 @@ def _categorize_snapshots(
586586
if not snapshot or not self._is_new_snapshot(snapshot):
587587
continue
588588

589-
forward_only = self._is_forward_only_change(s_id) or self._forward_only
589+
forward_only = self._forward_only or self._is_forward_only_change(s_id)
590+
if forward_only and s_id.name in self._context_diff.modified_snapshots:
591+
new, old = self._context_diff.modified_snapshots[s_id.name]
592+
if _should_force_rebuild(old, new) or snapshot.is_seed:
593+
# Breaking kind changes and seed changes can't be forward-only.
594+
forward_only = False
590595

591596
if s_id in self._choices:
592597
snapshot.categorize_as(self._choices[s_id], forward_only)
@@ -607,15 +612,10 @@ def _categorize_snapshot(
607612
s_id = snapshot.snapshot_id
608613

609614
if self._context_diff.directly_modified(s_id.name):
610-
new, old = self._context_diff.modified_snapshots[s_id.name]
611-
should_force_rebuild = _should_force_rebuild(old, new)
612-
if should_force_rebuild or snapshot.is_seed:
613-
# Breaking kind changes and seed changes can't be forward-only.
614-
forward_only = False
615-
616615
if self._auto_categorization_enabled:
617-
if should_force_rebuild:
618-
snapshot.categorize_as(SnapshotChangeCategory.BREAKING, forward_only)
616+
new, old = self._context_diff.modified_snapshots[s_id.name]
617+
if _should_force_rebuild(old, new):
618+
snapshot.categorize_as(SnapshotChangeCategory.BREAKING, False)
619619
return
620620

621621
s_id_with_missing_columns: t.Optional[SnapshotId] = None

tests/core/test_integration.py

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2557,8 +2557,6 @@ def test_virtual_environment_mode_dev_only_model_kind_change(init_and_plan_conte
25572557
assert len(data_objects) == 1
25582558
assert data_objects[0].type == "table"
25592559

2560-
context.state_sync.clear_cache()
2561-
25622560
# Change back to view
25632561
model = context.get_model("sushi.top_waiters")
25642562
model = model.copy(update={"kind": ViewKind()})
@@ -2605,6 +2603,46 @@ def test_virtual_environment_mode_dev_only_model_kind_change(init_and_plan_conte
26052603
assert data_objects[0].type == "table"
26062604

26072605

2606+
@time_machine.travel("2023-01-08 15:00:00 UTC")
2607+
def test_virtual_environment_mode_dev_only_model_kind_change_manual_categorization(
2608+
init_and_plan_context: t.Callable,
2609+
):
2610+
context, plan = init_and_plan_context(
2611+
"examples/sushi", config="test_config_virtual_environment_mode_dev_only"
2612+
)
2613+
context.apply(plan)
2614+
2615+
model = context.get_model("sushi.top_waiters")
2616+
model = model.copy(update={"kind": FullKind()})
2617+
context.upsert_model(model)
2618+
dev_plan_builder = context.plan_builder("dev", skip_tests=True, no_auto_categorization=True)
2619+
dev_plan_builder.set_choice(
2620+
dev_plan_builder._context_diff.snapshots[context.get_snapshot(model.name).snapshot_id],
2621+
SnapshotChangeCategory.NON_BREAKING,
2622+
)
2623+
dev_plan = dev_plan_builder.build()
2624+
assert dev_plan.requires_backfill
2625+
assert len(dev_plan.missing_intervals) == 1
2626+
context.apply(dev_plan)
2627+
2628+
prod_plan = context.plan_builder("prod", skip_tests=True).build()
2629+
assert prod_plan.requires_backfill
2630+
assert prod_plan.missing_intervals == [
2631+
SnapshotIntervals(
2632+
snapshot_id=context.get_snapshot("sushi.top_waiters").snapshot_id,
2633+
intervals=[
2634+
(to_timestamp("2023-01-01"), to_timestamp("2023-01-02")),
2635+
(to_timestamp("2023-01-02"), to_timestamp("2023-01-03")),
2636+
(to_timestamp("2023-01-03"), to_timestamp("2023-01-04")),
2637+
(to_timestamp("2023-01-04"), to_timestamp("2023-01-05")),
2638+
(to_timestamp("2023-01-05"), to_timestamp("2023-01-06")),
2639+
(to_timestamp("2023-01-06"), to_timestamp("2023-01-07")),
2640+
(to_timestamp("2023-01-07"), to_timestamp("2023-01-08")),
2641+
],
2642+
),
2643+
]
2644+
2645+
26082646
@time_machine.travel("2023-01-08 15:00:00 UTC")
26092647
def test_restatement_plan_ignores_changes(init_and_plan_context: t.Callable):
26102648
context, plan = init_and_plan_context("examples/sushi")

0 commit comments

Comments
 (0)