Skip to content

Commit 6d441e6

Browse files
committed
one more edge case
1 parent 6ef58cc commit 6d441e6

File tree

2 files changed

+47
-1
lines changed

2 files changed

+47
-1
lines changed

sqlmesh/core/scheduler.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -474,10 +474,17 @@ def run_merged_intervals(
474474
execution_time=execution_time,
475475
)
476476

477+
# We only need to create physical tables if the snapshot is not representative or if it
478+
# needs backfill
479+
snapshots_to_create_candidates = [
480+
s
481+
for s in selected_snapshots
482+
if not deployability_index.is_representative(s) or s in batched_intervals
483+
]
477484
snapshots_to_create = {
478485
s.snapshot_id
479486
for s in self.snapshot_evaluator.get_snapshots_to_create(
480-
selected_snapshots, deployability_index
487+
snapshots_to_create_candidates, deployability_index
481488
)
482489
}
483490

tests/core/test_integration.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2954,6 +2954,45 @@ def test_virtual_environment_mode_dev_only_seed_model_change(
29542954
assert actual_seed_df_in_prod.to_dict("records") == [{"id": 123, "name": "New Test Name"}]
29552955

29562956

2957+
@time_machine.travel("2023-01-08 15:00:00 UTC")
2958+
def test_virtual_environment_mode_dev_only_model_change_downstream_of_seed(
2959+
init_and_plan_context: t.Callable,
2960+
):
2961+
"""This test covers a scenario when a model downstream of a seed model is modified and explicitly selected
2962+
causing an (unhydrated) seed model to sourced from the state. If SQLMesh attempts to create
2963+
a table for the unchanged seed model, it will fail because the seed model is not hydrated.
2964+
"""
2965+
context, _ = init_and_plan_context(
2966+
"examples/sushi", config="test_config_virtual_environment_mode_dev_only"
2967+
)
2968+
context.load()
2969+
context.plan("prod", auto_apply=True, no_prompts=True)
2970+
2971+
# Make sure that a different version of the seed model is loaded
2972+
seed_model = context.get_model("sushi.waiter_names")
2973+
seed_model = seed_model.copy(update={"stamp": "force new version"})
2974+
context.upsert_model(seed_model)
2975+
2976+
# Make a change to the downstream model
2977+
model = context.get_model("sushi.waiter_as_customer_by_day")
2978+
model = model.copy(update={"stamp": "force new version"})
2979+
context.upsert_model(model)
2980+
2981+
# It is important to clear the cache so that the hydrated seed model is not sourced from the cache
2982+
context.clear_caches()
2983+
2984+
# Make sure to use the selector so that the seed model is sourced from the state
2985+
plan = context.plan_builder("dev", select_models=[model.name]).build()
2986+
assert len(plan.directly_modified) == 1
2987+
assert list(plan.directly_modified)[0].name == model.fqn
2988+
assert len(plan.missing_intervals) == 1
2989+
assert plan.missing_intervals[0].snapshot_id.name == model.fqn
2990+
2991+
# Make sure there's no error when applying the plan
2992+
context.apply(plan)
2993+
context.plan("prod", auto_apply=True, no_prompts=True)
2994+
2995+
29572996
@time_machine.travel("2023-01-08 15:00:00 UTC")
29582997
def test_restatement_plan_ignores_changes(init_and_plan_context: t.Callable):
29592998
context, plan = init_and_plan_context("examples/sushi")

0 commit comments

Comments
 (0)