Skip to content

Commit 1837bb6

Browse files
authored
Fix: Recreate views even if the change was categorized as indirect non-breaking to update table references (#4414)
1 parent 0150154 commit 1837bb6

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

sqlmesh/core/snapshot/evaluator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -902,7 +902,7 @@ def _migrate_snapshot(
902902
if (
903903
not snapshot.is_paused
904904
or not snapshot.is_model
905-
or deployability_index.is_representative(snapshot)
905+
or (deployability_index.is_representative(snapshot) and not snapshot.is_view)
906906
):
907907
return
908908

tests/core/test_integration.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4279,6 +4279,28 @@ def test_full_model_change_with_plan_start_not_matching_model_start(
42794279
assert row_num > 0
42804280

42814281

4282+
@time_machine.travel("2023-01-08 15:00:00 UTC")
4283+
def test_indirect_non_breaking_view_is_updated_with_new_table_references(
4284+
init_and_plan_context: t.Callable,
4285+
):
4286+
context, plan = init_and_plan_context("examples/sushi")
4287+
context.apply(plan)
4288+
4289+
# Add a new projection to the base model
4290+
model = context.get_model("sushi.waiter_revenue_by_day")
4291+
context.upsert_model(add_projection_to_model(t.cast(SqlModel, model)))
4292+
4293+
context.plan("prod", auto_apply=True, no_prompts=True, skip_tests=True)
4294+
4295+
# Run the janitor to delete the old snapshot record
4296+
context.run_janitor(ignore_ttl=True)
4297+
4298+
# Check the downstream view and make sure it's still queryable
4299+
assert context.get_model("sushi.top_waiters").kind.is_view
4300+
row_num = context.engine_adapter.fetchone(f"SELECT COUNT(*) FROM sushi.top_waiters")[0]
4301+
assert row_num > 0
4302+
4303+
42824304
@time_machine.travel("2023-01-08 15:00:00 UTC")
42834305
def test_dbt_requirements(sushi_dbt_context: Context):
42844306
assert set(sushi_dbt_context.requirements) == {"dbt-core", "dbt-duckdb"}

0 commit comments

Comments
 (0)