Skip to content

fix: raise SQLMeshError when invalidating a nonexistent environment#5833

Open
noezhiya-dot wants to merge 3 commits into
SQLMesh:mainfrom
noezhiya-dot:fix/invalidate-nonexistent-environment
Open

fix: raise SQLMeshError when invalidating a nonexistent environment#5833
noezhiya-dot wants to merge 3 commits into
SQLMesh:mainfrom
noezhiya-dot:fix/invalidate-nonexistent-environment

Conversation

@noezhiya-dot

Copy link
Copy Markdown

Description

The sqlmesh invalidate command previously accepted any environment name, even if the environment did not exist, silently reporting success. Now it checks that the environment exists first and raises a clear SQLMeshError if it does not.

Test Plan

  • Added test_invalidate_environment_nonexistent_raises to confirm that calling invalidate_environment on a nonexistent environment raises SQLMeshError and does not call invalidate_environment on the state sync.
  • Existing tests for valid environments remain unchanged.

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

noezhiya-dot and others added 2 commits June 10, 2026 03:08
The sqlmesh invalidate command previously accepted any environment name,
even if the environment did not exist, silently reporting success. Now
it checks that the environment exists first and raises a clear
SQLMeshError if it does not.

Fixes SQLMesh#5621

Signed-off-by: Nuzia Rijki <noezhiya@gmail.com>
Comment thread sqlmesh/core/context.py
name = Environment.sanitize_name(name)
stored_environment = self.state_sync.get_environment(name)
if not stored_environment:
raise SQLMeshError(f"Environment '{name}' does not exist.")

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see a warning as a better option here instead of an error. If there's some CICD script running, we wouldn't want them to fail when they're trying to ensure proper cleanup.

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.

2 participants