Skip to content

Commit 6201a76

Browse files
committed
Warn instead of raising or overwriting state
1 parent 0943541 commit 6201a76

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed

sqlmesh/migrations/v0087_normalize_blueprint_variables.py

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from dataclasses import dataclass
1818

1919
from sqlglot import exp
20+
from sqlmesh.core.console import get_console
2021
from sqlmesh.utils.migration import index_text_type, blob_text_type
2122

2223

@@ -74,25 +75,25 @@ def migrate(state_sync, **kwargs): # type: ignore
7475
node = parsed_snapshot["node"]
7576
python_env = node.get("python_env") or {}
7677

77-
# Intentionally checking for falsey value here, since that accounts for empty dicts and None
7878
if blueprint_vars_executable := python_env.get(SQLMESH_BLUEPRINT_VARS):
7979
blueprint_vars = eval(blueprint_vars_executable["payload"])
8080

8181
for var, value in dict(blueprint_vars).items():
8282
lowercase_var = var.lower()
8383
if var != lowercase_var:
84-
# Ensures that we crash instead of overwriting snapshot payloads incorrectly
85-
assert lowercase_var not in blueprint_vars, (
86-
"SQLMesh could not migrate the state database successfully, because it detected "
87-
f"two different blueprint variable names ('{var}' and '{lowercase_var}') that resolve "
88-
f"to the same name ('{lowercase_var}') for model '{node['name']}'. Downgrade the local "
89-
"SQLMesh version to the previously-installed one, rename either of these variables, "
90-
"apply the corresponding plan and try again."
91-
)
92-
93-
del blueprint_vars[var]
94-
blueprint_vars[lowercase_var] = value
95-
migration_needed = True
84+
if lowercase_var in blueprint_vars:
85+
get_console().log_warning(
86+
"SQLMesh is unable to fully migrate the state database, because the "
87+
f"model '{node['name']}' contains two blueprint variables ('{var}' and "
88+
f"'{lowercase_var}') that resolve to the same value ('{lowercase_var}'). "
89+
"This may result in unexpected changes being reported by the next "
90+
"`sqlmesh plan` command. If this happens, consider renaming either variable, "
91+
"so that the lowercase version of their names are different."
92+
)
93+
else:
94+
del blueprint_vars[var]
95+
blueprint_vars[lowercase_var] = value
96+
migration_needed = True
9697

9798
if migration_needed:
9899
blueprint_vars_executable["payload"] = repr(blueprint_vars)

0 commit comments

Comments
 (0)