Skip to content

Commit f92dfd1

Browse files
authored
Reapply "fix!: dont normalize model meta and lower audit args" (#2559)
This reverts commit c48754f.
1 parent c48754f commit f92dfd1

File tree

4 files changed

+16
-5
lines changed

4 files changed

+16
-5
lines changed

sqlmesh/core/model/definition.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1457,6 +1457,7 @@ def load_sql_based_model(
14571457
python_env=meta_python_env,
14581458
default_catalog=default_catalog,
14591459
quote_identifiers=False,
1460+
normalize_identifiers=False,
14601461
)
14611462
rendered_meta_exprs = meta_renderer.render()
14621463
if rendered_meta_exprs is None or len(rendered_meta_exprs) != 1:

sqlmesh/core/model/meta.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ def extract(v: exp.Expression) -> t.Tuple[str, t.Dict[str, exp.Expression]]:
9393
raise ConfigError(
9494
f"Function '{func}' must be called with key-value arguments like {func}(arg := value)."
9595
)
96-
kwargs[arg.left.name] = arg.right
96+
kwargs[arg.left.name.lower()] = arg.right
9797
return func.lower(), kwargs
9898

9999
if isinstance(v, (exp.Tuple, exp.Array)):

sqlmesh/core/renderer.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ def __init__(
4848
default_catalog: t.Optional[str] = None,
4949
quote_identifiers: bool = True,
5050
model_fqn: t.Optional[str] = None,
51+
normalize_identifiers: bool = True,
5152
):
5253
self._expression = expression
5354
self._dialect = dialect
@@ -57,6 +58,7 @@ def __init__(
5758
self._python_env = python_env or {}
5859
self._only_execution_time = only_execution_time
5960
self._default_catalog = default_catalog
61+
self._normalize_identifiers = normalize_identifiers
6062
self._quote_identifiers = quote_identifiers
6163
self.update_schema({} if schema is None else schema)
6264
self._cache: t.List[t.Optional[exp.Expression]] = []
@@ -288,9 +290,12 @@ def _expand(node: exp.Expression) -> exp.Expression:
288290

289291
@contextmanager
290292
def _normalize_and_quote(self, query: E) -> t.Iterator[E]:
291-
with d.normalize_and_quote(
292-
query, self._dialect, self._default_catalog, quote=self._quote_identifiers
293-
) as query:
293+
if self._normalize_identifiers:
294+
with d.normalize_and_quote(
295+
query, self._dialect, self._default_catalog, quote=self._quote_identifiers
296+
) as query:
297+
yield query
298+
else:
294299
yield query
295300

296301
def _should_cache(self, runtime_stage: RuntimeStage, *args: t.Any) -> bool:

tests/core/test_model.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2289,14 +2289,19 @@ def test_model_normalization():
22892289
MODEL (
22902290
name foo,
22912291
dialect snowflake,
2292-
kind INCREMENTAL_BY_UNIQUE_KEY(unique_key a)
2292+
kind INCREMENTAL_BY_UNIQUE_KEY(unique_key a),
2293+
audits (
2294+
not_null(COLUMNS := id)
2295+
),
22932296
);
22942297
22952298
SELECT x.a AS a FROM test.x AS x
22962299
"""
22972300
)
22982301
model = SqlModel.parse_raw(load_sql_based_model(expr).json())
22992302
assert model.unique_key == [exp.column("A", quoted=True)]
2303+
# we should never normalize the model meta, additionally, we should force lower case
2304+
assert model.audits[0][1] == {"columns": exp.column("id")}
23002305

23012306
model = create_sql_model(
23022307
"foo",

0 commit comments

Comments
 (0)