Skip to content

Commit 751cee9

Browse files
committed
Ensure plan option does not work if target env == create_from
1 parent fbe0543 commit 751cee9

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

sqlmesh/core/context_diff.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,9 @@ def create(
132132
existing_env = state_reader.get_environment(environment)
133133
create_from_env_exists = False
134134

135-
if existing_env is None or existing_env.expired or always_recreate_environment:
135+
recreate_environment = always_recreate_environment and not environment == create_from
136+
137+
if existing_env is None or existing_env.expired or recreate_environment:
136138
env = state_reader.get_environment(create_from.lower())
137139

138140
if not env and create_from != c.PROD:

tests/core/test_integration.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6345,7 +6345,11 @@ def plan_with_output(ctx: Context, environment: str):
63456345
in output.stdout
63466346
)
63476347

6348-
# Case 6: Check that we can still run Context::diff() against any environment
6348+
# Case 6: Ensure that target environment and create_from environment are not the same
6349+
output = plan_with_output(ctx, "prod")
6350+
assert not "New environment `prod` will be created from `prod`" in output.stdout
6351+
6352+
# Case 7: Check that we can still run Context::diff() against any environment
63496353
for environment in ["dev", "prod"]:
63506354
context_diff = ctx._context_diff(environment)
63516355
assert context_diff.environment == environment

0 commit comments

Comments
 (0)