Skip to content

Fix: allow --select-model to plan a model deletion#5759

Open
viniciusnunest wants to merge 1 commit intoSQLMesh:mainfrom
viniciusnunest:fix/5741-select-model-deletion
Open

Fix: allow --select-model to plan a model deletion#5759
viniciusnunest wants to merge 1 commit intoSQLMesh:mainfrom
viniciusnunest:fix/5741-select-model-deletion

Conversation

@viniciusnunest
Copy link
Copy Markdown

Description

Fixes #5741

Right now if you delete a model file locally and try to plan its removal with
--select-model=<deleted-model>, you get:

PlanError: Selector did not return any models.

The problem is that expand_model_selections only looks at local models. Since
the file is gone, it finds nothing, backfill_models ends up empty, and
_plan() raises. The workaround was adding some unrelated active model to the
selection, which works but it is not great.

The thing is, the underlying machinery already handles deletions fine. When
backfill_models has at least one entry, deleted models show up correctly in
context_diff.removed_snapshots. So the fix is about making the selector and
plan validation aware that "no local matches" can still be valid when matching
models pending deletion in the deployed environment.

Changes:

  • Extracted _load_env_models() from select_models() to avoid duplicating
    the environment loading logic
  • Added expand_model_selections_with_env() that expands selections against
    both local and environment models
  • In _plan(), when backfill_models is empty, it now checks whether the
    selection matched models in the environment that were deleted locally. If so,
    PlanError is suppressed and the deletions surface via removed_snapshots
  • Selecting a model that exists neither locally nor in the environment still
    raises PlanError as before

Test Plan

  • test_expand_model_selections_with_env: deleted models found in env, local
    models still work, wildcards match, non-existent returns empty
  • test_expand_model_selections_with_env_fallback: fallback environment is used
    when target env is missing
  • test_expand_model_selections_with_env_expired: expired environments ignored
  • test_plan_select_model_deleted_model: end-to-end with the sushi example,
    deploys to prod, deletes model file, reloads, runs plan and checks that the
    model appears in removed_snapshots
  • test_plan_select_model_deleted_model_still_rejects_nonexistent: negative
    case, makes sure garbage input still fails

Checklist

  • I have run make style and fixed any issues
  • I have added tests for my changes (if applicable)
  • All existing tests pass (make fast-test)
  • My commits are signed off (git commit -s) per the DCO

When a model file is deleted locally but still exists in the deployed
environment, --select-model now correctly plans the removal instead of
raising PlanError.

Fixes SQLMesh#5741

Signed-off-by: vinicius <viniciusnunes.tavares@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

--select-model cannot plan a model deletion without an active model in the same selection

1 participant