Skip to content

sqlmesh format corrupts MODEL meta expressions (ignored_rules + DATE_TRUNC for BigQuery) #6035

Description

@cuong0993

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions