From b87dfc606aabf10f81a82e881929306b2cc1869e Mon Sep 17 00:00:00 2001 From: Iaroslav Zeigerman Date: Mon, 15 Sep 2025 15:16:42 -0700 Subject: [PATCH 1/2] Fix: Modifying a standalone audit when using the dev-only virtual environment mode --- sqlmesh/core/plan/common.py | 6 ++++++ tests/core/test_integration.py | 27 ++++++++++++++++++++++++++- 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/sqlmesh/core/plan/common.py b/sqlmesh/core/plan/common.py index 4ae8a3112c..45ba277dbb 100644 --- a/sqlmesh/core/plan/common.py +++ b/sqlmesh/core/plan/common.py @@ -23,6 +23,12 @@ def should_force_rebuild(old: Snapshot, new: Snapshot) -> bool: def is_breaking_kind_change(old: Snapshot, new: Snapshot) -> bool: + if new.is_model != old.is_model: + # If one is a model and the other isn't, then we need to rebuild + return True + if not new.is_model or not old.is_model: + # If neither are models, then we don't need to rebuild + return False if old.virtual_environment_mode != new.virtual_environment_mode: # If the virtual environment mode has changed, then we need to rebuild return True diff --git a/tests/core/test_integration.py b/tests/core/test_integration.py index 0fad472cd5..c2c11ced80 100644 --- a/tests/core/test_integration.py +++ b/tests/core/test_integration.py @@ -3116,7 +3116,32 @@ def test_virtual_environment_mode_dev_only_model_change_downstream_of_seed( # Make sure there's no error when applying the plan context.apply(plan) - context.plan("prod", auto_apply=True, no_prompts=True) + + +@time_machine.travel("2023-01-08 15:00:00 UTC") +def test_virtual_environment_mode_dev_only_model_change_standalone_audit( + init_and_plan_context: t.Callable, +): + context, plan = init_and_plan_context( + "examples/sushi", config="test_config_virtual_environment_mode_dev_only" + ) + context.apply(plan) + + # Change a model upstream from a standalone audit + model = context.get_model("sushi.items") + model = model.copy(update={"stamp": "force new version"}) + context.upsert_model(model) + + plan = context.plan_builder("prod", skip_tests=True).build() + + # Make sure the standalone audit is among modified + assert ( + context.get_snapshot("assert_item_price_above_zero").snapshot_id + in plan.indirectly_modified[context.get_snapshot("sushi.items").snapshot_id] + ) + + # Make sure there's no error when applying the plan + context.apply(plan) @time_machine.travel("2023-01-08 15:00:00 UTC") From 57e2d308c278c946403bd4275d1a23d77cdb4220 Mon Sep 17 00:00:00 2001 From: Iaroslav Zeigerman Date: Mon, 15 Sep 2025 15:22:51 -0700 Subject: [PATCH 2/2] improve comment --- sqlmesh/core/plan/common.py | 1 + 1 file changed, 1 insertion(+) diff --git a/sqlmesh/core/plan/common.py b/sqlmesh/core/plan/common.py index 45ba277dbb..99601cb484 100644 --- a/sqlmesh/core/plan/common.py +++ b/sqlmesh/core/plan/common.py @@ -28,6 +28,7 @@ def is_breaking_kind_change(old: Snapshot, new: Snapshot) -> bool: return True if not new.is_model or not old.is_model: # If neither are models, then we don't need to rebuild + # Note that the remaining checks only apply to model snapshots return False if old.virtual_environment_mode != new.virtual_environment_mode: # If the virtual environment mode has changed, then we need to rebuild