Skip to content

Commit 997f05d

Browse files
committed
Fix: Create empty physical tables for fully annotated self-referential models
1 parent dbc7de6 commit 997f05d

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

sqlmesh/core/snapshot/evaluator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -750,7 +750,7 @@ def _evaluate_snapshot(
750750
model.kind.is_materialized
751751
and model.columns_to_types_
752752
and columns_to_types_all_known(model.columns_to_types_)
753-
)
753+
) or (model.depends_on_self and model.annotated)
754754
if self._can_clone(snapshot, deployability_index):
755755
self._clone_snapshot_in_dev(
756756
snapshot=snapshot,

tests/core/test_integration.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -980,6 +980,32 @@ def test_new_forward_only_model(init_and_plan_context: t.Callable):
980980
assert context.engine_adapter.table_exists(snapshot.table_name(is_deployable=False))
981981

982982

983+
@time_machine.travel("2023-01-08 00:00:00 UTC")
984+
def test_annotated_self_referential_model(init_and_plan_context: t.Callable):
985+
context, _ = init_and_plan_context("examples/sushi")
986+
987+
# Projections are fully annotated in the query but columns were not specified explicitly
988+
expressions = d.parse(
989+
f"""
990+
MODEL (
991+
name memory.sushi.test_self_ref,
992+
kind FULL,
993+
start '2023-01-01',
994+
);
995+
996+
SELECT 1::INT AS one FROM memory.sushi.test_self_ref;
997+
"""
998+
)
999+
model = load_sql_based_model(expressions)
1000+
assert model.depends_on_self
1001+
context.upsert_model(model)
1002+
1003+
context.plan("prod", skip_tests=True, no_prompts=True, auto_apply=True)
1004+
1005+
df = context.fetchdf("SELECT one FROM memory.sushi.test_self_ref")
1006+
assert len(df) == 0
1007+
1008+
9831009
@time_machine.travel("2023-01-08 15:00:00 UTC")
9841010
def test_plan_set_choice_is_reflected_in_missing_intervals(init_and_plan_context: t.Callable):
9851011
context, _ = init_and_plan_context("examples/sushi")

0 commit comments

Comments
 (0)