Skip to content

Commit 0181bb5

Browse files
committed
Feat: Allow creating environments without changes when using selector (#3060)
1 parent 6f3c0af commit 0181bb5

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

sqlmesh/core/plan/builder.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -672,6 +672,7 @@ def _ensure_new_env_with_changes(self) -> None:
672672
and not self._include_unmodified
673673
and self._context_diff.is_new_environment
674674
and not self._context_diff.has_snapshot_changes
675+
and not self._backfill_models
675676
):
676677
raise NoChangesPlanError(
677678
"No changes were detected. Make a change or run with --include-unmodified to create a new environment without changes."

tests/core/test_integration.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
SnapshotTableInfo,
5252
)
5353
from sqlmesh.utils.date import TimeLike, now, to_date, to_datetime, to_timestamp
54+
from sqlmesh.utils.errors import NoChangesPlanError
5455
from tests.conftest import DuckDBMetadata, SushiDataValidator
5556

5657

@@ -1627,6 +1628,22 @@ def test_plan_twice_with_star_macro_yields_no_diff(tmp_path: Path):
16271628
assert not new_plan.new_snapshots
16281629

16291630

1631+
@freeze_time("2023-01-08 15:00:00")
1632+
def test_create_environment_no_changes_with_selector(init_and_plan_context: t.Callable):
1633+
context, plan = init_and_plan_context("examples/sushi")
1634+
context.apply(plan)
1635+
1636+
with pytest.raises(NoChangesPlanError):
1637+
context.plan("dev", no_prompts=True)
1638+
1639+
plan = context.plan("dev", no_prompts=True, select_models=["*top_waiters"])
1640+
assert not plan.missing_intervals
1641+
context.apply(plan)
1642+
1643+
schema_objects = context.engine_adapter.get_data_objects("sushi__dev")
1644+
assert {o.name for o in schema_objects} == {"top_waiters"}
1645+
1646+
16301647
@pytest.mark.parametrize(
16311648
"context_fixture",
16321649
["sushi_context", "sushi_dbt_context", "sushi_test_dbt_context", "sushi_no_default_catalog"],

0 commit comments

Comments
 (0)