Bug: --select-model cannot plan a model deletion without an active model in the same selection
Describe the bug
When a model file is deleted from the project and you attempt to plan its removal using
--select-model=<model-name>, SQLMesh raises:
Error: Selector did not return any models. Please check your model selection and try again.
This happens regardless of whether the deletion is unstaged, staged, or committed.
Root cause
In selector.py, get_model() returns None for any model matched via env_models (the
deployed environment state) that is absent from self._models (current project files). Because
the file is deleted, it cannot be in self._models. The model is excluded from
models_override, so backfill_models ends up empty. context._plan() then raises PlanError
when it detects backfill_models is not None and not backfill_models.
Workaround
The deletion appears in the plan if at least one other active (non-deleted) model is also
selected. In that case backfill_models is non-empty, the deleted model is excluded from
models_override, and ContextDiff naturally surfaces it in removed_snapshots.
sqlmesh plan --select-model=<deleted-model> --select-model=<any-active-model>
This is fragile — it requires the user to know about the constraint and artificially include an
unrelated model.
▎ Note: The git:master selector uses --diff-filter=d on all its git diff calls, which
▎ explicitly excludes deleted files. There is currently no selector-based path that can surface a
▎ model deletion without an active model alongside it.
Expected behavior
--select-model= should be sufficient to plan a model removal when that
model exists in the deployed environment state, without requiring an unrelated active model in
the selection.
Steps to reproduce
- Deploy a model to an environment
- Delete the model's .sql file from the project
- Run sqlmesh plan --select-model=
- Observe: PlanError: Selector did not return any models
- Add any other active model: sqlmesh plan --select-model= --select-model=
- Observe: deletion appears in the plan correctly
Environment
- SQLMesh Core: 0.230.1
- Tobiko Cloud Enterprise: 202608.1.0+534bbc3
Bug:
--select-modelcannot plan a model deletion without an active model in the same selectionDescribe the bug
When a model file is deleted from the project and you attempt to plan its removal using
--select-model=<model-name>, SQLMesh raises:Error: Selector did not return any models. Please check your model selection and try again.
This happens regardless of whether the deletion is unstaged, staged, or committed.
Root cause
In
selector.py,get_model()returnsNonefor any model matched viaenv_models(thedeployed environment state) that is absent from
self._models(current project files). Becausethe file is deleted, it cannot be in
self._models. The model is excluded frommodels_override, sobackfill_modelsends up empty.context._plan()then raisesPlanErrorwhen it detects
backfill_models is not None and not backfill_models.Workaround
The deletion appears in the plan if at least one other active (non-deleted) model is also
selected. In that case
backfill_modelsis non-empty, the deleted model is excluded frommodels_override, andContextDiffnaturally surfaces it inremoved_snapshots.This is fragile — it requires the user to know about the constraint and artificially include an
unrelated model.
▎ Note: The git:master selector uses --diff-filter=d on all its git diff calls, which
▎ explicitly excludes deleted files. There is currently no selector-based path that can surface a
▎ model deletion without an active model alongside it.
Expected behavior
--select-model= should be sufficient to plan a model removal when that
model exists in the deployed environment state, without requiring an unrelated active model in
the selection.
Steps to reproduce
Environment
- SQLMesh Core: 0.230.1
- Tobiko Cloud Enterprise: 202608.1.0+534bbc3