Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions sqlmesh/core/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -1341,6 +1341,13 @@ def plan_builder(
if restate_models is not None:
expanded_restate_models = model_selector.expand_model_selections(restate_models)

if (restate_models is not None and not expanded_restate_models) or (
backfill_models is not None and not backfill_models
):
raise PlanError(
"Selector did not return any models. Please check your model selection and try again."
)

snapshots = self._snapshots(models_override)
context_diff = self._context_diff(
environment or c.PROD,
Expand Down
22 changes: 21 additions & 1 deletion tests/core/test_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
to_timestamp,
yesterday_ds,
)
from sqlmesh.utils.errors import ConfigError, SQLMeshError, LinterError
from sqlmesh.utils.errors import ConfigError, SQLMeshError, LinterError, PlanError
from sqlmesh.utils.metaprogramming import Executable
from tests.utils.test_helpers import use_terminal_console
from tests.utils.test_filesystem import create_temp_file
Expand Down Expand Up @@ -1786,3 +1786,23 @@ def model5_entrypoint(context, **kwargs):
)

sushi_context.upsert_model(model5)


def test_plan_selector_expression_no_match(sushi_context: Context) -> None:
with pytest.raises(
PlanError,
match="Selector did not return any models. Please check your model selection and try again.",
):
sushi_context.plan("dev", select_models=["*missing*"])

with pytest.raises(
PlanError,
match="Selector did not return any models. Please check your model selection and try again.",
):
sushi_context.plan("dev", backfill_models=["*missing*"])

with pytest.raises(
PlanError,
match="Selector did not return any models. Please check your model selection and try again.",
):
sushi_context.plan("prod", restate_models=["*missing*"])
18 changes: 10 additions & 8 deletions tests/core/test_plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -779,15 +779,17 @@ def test_restate_models(sushi_context_pre_scheduling: Context):
'"memory"."sushi"."waiter_revenue_by_day"',
}

plan = sushi_context_pre_scheduling.plan(restate_models=["unknown_model"], no_prompts=True)
assert not plan.has_changes
assert not plan.restatements
assert plan.models_to_backfill is None
with pytest.raises(
PlanError,
match="Selector did not return any models. Please check your model selection and try again.",
):
sushi_context_pre_scheduling.plan(restate_models=["unknown_model"], no_prompts=True)

plan = sushi_context_pre_scheduling.plan(restate_models=["tag:unknown_tag"], no_prompts=True)
assert not plan.has_changes
assert not plan.restatements
assert plan.models_to_backfill is None
with pytest.raises(
PlanError,
match="Selector did not return any models. Please check your model selection and try again.",
):
sushi_context_pre_scheduling.plan(restate_models=["tag:unknown_tag"], no_prompts=True)

plan = sushi_context_pre_scheduling.plan(restate_models=["raw.demographics"], no_prompts=True)
assert not plan.has_changes
Expand Down