|
17 | 17 | from dataclasses import dataclass |
18 | 18 |
|
19 | 19 | from sqlglot import exp |
| 20 | +from sqlmesh.core.console import get_console |
20 | 21 | from sqlmesh.utils.migration import index_text_type, blob_text_type |
21 | 22 |
|
22 | 23 |
|
@@ -74,25 +75,25 @@ def migrate(state_sync, **kwargs): # type: ignore |
74 | 75 | node = parsed_snapshot["node"] |
75 | 76 | python_env = node.get("python_env") or {} |
76 | 77 |
|
77 | | - # Intentionally checking for falsey value here, since that accounts for empty dicts and None |
78 | 78 | if blueprint_vars_executable := python_env.get(SQLMESH_BLUEPRINT_VARS): |
79 | 79 | blueprint_vars = eval(blueprint_vars_executable["payload"]) |
80 | 80 |
|
81 | 81 | for var, value in dict(blueprint_vars).items(): |
82 | 82 | lowercase_var = var.lower() |
83 | 83 | 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 |
96 | 97 |
|
97 | 98 | if migration_needed: |
98 | 99 | blueprint_vars_executable["payload"] = repr(blueprint_vars) |
|
0 commit comments