Skip to content

Commit 1667540

Browse files
committed
Fix: Expand the parent's model query during query rendering if the parent is not categorized
1 parent da8e091 commit 1667540

4 files changed

Lines changed: 28 additions & 1 deletion

File tree

sqlmesh/core/engine_adapter/base.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ def with_log_level(self, level: int) -> EngineAdapter:
152152
register_comments=self._register_comments,
153153
null_connection=True,
154154
multithreaded=self._multithreaded,
155+
pretty_sql=self._pretty_sql,
155156
**self._extra_config,
156157
)
157158

sqlmesh/core/renderer.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,9 @@ def _resolve_tables(
317317
**table_mapping,
318318
}
319319
expand = set(expand) | {
320-
name for name, snapshot in snapshots.items() if snapshot.is_embedded
320+
name
321+
for name, snapshot in snapshots.items()
322+
if snapshot.is_embedded or not snapshot.categorized
321323
}
322324

323325
if expand:

sqlmesh/core/snapshot/definition.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1014,6 +1014,11 @@ def categorize_as(self, category: SnapshotChangeCategory) -> None:
10141014

10151015
self.change_category = category
10161016

1017+
@property
1018+
def categorized(self) -> bool:
1019+
"""Whether the snapshot has been categorized."""
1020+
return self.change_category is not None and self.version is not None
1021+
10171022
def table_name(self, is_deployable: bool = True) -> str:
10181023
"""Full table name pointing to the materialized location of the snapshot.
10191024

tests/core/test_integration.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4075,6 +4075,25 @@ def test_no_backfill_for_model_downstream_of_metadata_change(init_and_plan_conte
40754075
)
40764076

40774077

4078+
@time_machine.travel("2023-01-08 15:00:00 UTC")
4079+
def test_evaluate_of_uncategorized_snapshot(init_and_plan_context: t.Callable):
4080+
context, plan = init_and_plan_context("examples/sushi")
4081+
context.apply(plan)
4082+
4083+
# Add a new projection
4084+
model = context.get_model("sushi.waiter_revenue_by_day")
4085+
context.upsert_model(add_projection_to_model(t.cast(SqlModel, model)))
4086+
4087+
# Downstream model references the new projection
4088+
downstream_model = context.get_model("sushi.top_waiters")
4089+
context.upsert_model(add_projection_to_model(t.cast(SqlModel, downstream_model), literal=False))
4090+
4091+
df = context.evaluate(
4092+
"sushi.top_waiters", start="2023-01-05", end="2023-01-06", execution_time=now()
4093+
)
4094+
assert set(df["one"].tolist()) == {1}
4095+
4096+
40784097
@time_machine.travel("2023-01-08 15:00:00 UTC")
40794098
def test_dbt_requirements(sushi_dbt_context: Context):
40804099
assert set(sushi_dbt_context.requirements) == {"dbt-core", "dbt-duckdb"}

0 commit comments

Comments
 (0)