Version: sqlmesh >= 0.236.0
Command: sqlmesh format
Config: connection.type: bigquery
Reproduction
After format, these files are incorrectly rewritten:
- ignored_rules ['nomissingaudits'],
+ ignored_rules ARRAY('nomissingaudits'),
- partitioned_by DATE_TRUNC(date, MONTH),
+ partitioned_by DATE_TRUNC('MONTH', date),
The DATE_TRUNC swap causes parsing failure:
Error: Failed to load model from file '.../....sql':
Field 'DATE_TRUNC('DATE', 'MONTH')' does not contain a column
Root cause (stack / source)
File: .venv/lib/python3.14/site-packages/sqlmesh/core/dialect.py
Function: format_model_expressions() (line ~823)
return ";\n\n".join(
expression.sql(
pretty=True,
dialect=None if is_meta_expression(expression) else dialect, # <-- BUG
normalize_functions=normalize_functions,
**kwargs,
)
...
)
Meta expressions (MODEL (...)) are rendered with dialect=None regardless of gateway/dialect. When SQLGlot generates DATE_TRUNC with no dialect, it produces DATE_TRUNC('MONTH', date) (generic syntax). Similarly array literals become ARRAY(...).
Call path (from context.py):
context.format() → _format() (line 1372) → format_model_expressions(expressions, transpile or target.dialect, ...) → expression.sql(dialect=None if is_meta_expression(..) else dialect)
Expected
sqlmesh format should preserve BigQuery meta-expression syntax:
ignored_rules ['nomissingaudits']
partitioned_by DATE_TRUNC(date, MONTH)
Actual
Meta expressions rewritten to generic SQLGlot default syntax, breaking BigQuery model loads.
Version: sqlmesh >= 0.236.0
Command:
sqlmesh formatConfig:
connection.type: bigqueryReproduction
After format, these files are incorrectly rewritten:
The DATE_TRUNC swap causes parsing failure:
Root cause (stack / source)
File:
.venv/lib/python3.14/site-packages/sqlmesh/core/dialect.pyFunction:
format_model_expressions()(line ~823)Meta expressions (
MODEL (...)) are rendered withdialect=Noneregardless of gateway/dialect. When SQLGlot generatesDATE_TRUNCwith no dialect, it producesDATE_TRUNC('MONTH', date)(generic syntax). Similarly array literals becomeARRAY(...).Call path (from
context.py):context.format()→_format()(line 1372) →format_model_expressions(expressions, transpile or target.dialect, ...)→expression.sql(dialect=None if is_meta_expression(..) else dialect)Expected
sqlmesh formatshould preserve BigQuery meta-expression syntax:ignored_rules ['nomissingaudits']partitioned_by DATE_TRUNC(date, MONTH)Actual
Meta expressions rewritten to generic SQLGlot default syntax, breaking BigQuery model loads.