fix(format): keep MODEL/AUDIT/METRIC header dialect-agnostic (#5773) - #5864
Merged
Conversation
StuffbyYuki
self-requested a review
June 29, 2026 19:36
StuffbyYuki
approved these changes
Jun 29, 2026
StuffbyYuki
left a comment
Collaborator
There was a problem hiding this comment.
@anxkhn Thanks for this PR!
Optional: AUDIT/false boolean test cases; text_diff may deserve the same treatment in a follow-up.
format_model_expressions rendered every parsed expression with the target dialect, including the SQLMesh-specific MODEL/AUDIT/METRIC header. That header is SQLMesh DDL, not standard SQL, so transpiling it corrupts boolean properties: under tsql (which has no TRUE keyword) a property like `allow_partials true` was rewritten to `allow_partials (1 = 1)`. Render meta expressions (is_meta_expression) with dialect=None so the header stays as written, while the actual query/statement body still transpiles to the target dialect. Signed-off-by: Anas Khan <83116240+anxkhn@users.noreply.github.com>
anxkhn
force-pushed
the
loop/sqlmesh__001
branch
from
June 30, 2026 04:21
f6078cd to
5fc0cf8
Compare
EhabEasee
pushed a commit
to EhabEasee/sqlmesh
that referenced
this pull request
Jun 30, 2026
…#5773) (SQLMesh#5864) Signed-off-by: Anas Khan <83116240+anxkhn@users.noreply.github.com> Signed-off-by: EhabEasee <ehab.elbadrawi@easee.com>
fresioAS
pushed a commit
to fresioAS/sqlmesh
that referenced
this pull request
Jul 13, 2026
…#5773) (SQLMesh#5864) Signed-off-by: Anas Khan <83116240+anxkhn@users.noreply.github.com> Signed-off-by: fresioAS <andreas.fredhoi@three60energy.com>
4 tasks
4 tasks
mday-io
pushed a commit
to mday-io/sqlmesh
that referenced
this pull request
Aug 9, 2026
Cherry-picked from upstream sqlmesh/sqlmesh commit c3ec643 (fix(format): keep MODEL/AUDIT/METRIC header dialect-agnostic (SQLMesh#5773) (SQLMesh#5864)), which this fork's main had not yet synced. Needed as a prerequisite for the follow-up fixes to header property rendering. Meta expressions (MODEL/AUDIT/METRIC) are SQLMesh DDL, not standard SQL, so they must never be transpiled to the target dialect -- e.g. tsql would rewrite a boolean property like `allow_partials TRUE` to `(1 = 1)`. Signed-off-by: mday-io <mdaytn@gmail.com> Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016cYEi6jnceseL6gRSPM5i9
mday-io
added a commit
to mday-io/sqlmesh
that referenced
this pull request
Aug 9, 2026
…alect SQLMesh#5864 stopped transpiling MODEL/AUDIT/METRIC headers so that SQLMesh's own boolean properties would survive formatting -- on tsql, `allow_partials TRUE` was being rewritten to `(1 = 1)`, which then fails to parse at all and leaves the model file broken. That fix rendered the entire header generically, including the properties whose values are the user's warehouse SQL. Those lose their dialect: `columns (ts DATETIME2(6))` becomes `TIMESTAMP(6)`, and an audit argument such as `CAST('2024-01-01' AS DATETIME2)` is silently downgraded the same way. Split the header per property instead of per expression. The split is derived from the field declarations themselves: expression-typed fields (columns, audits, signals, partitioned_by, physical_properties, ...) hold warehouse SQL and render with the model dialect, while scalar-typed fields (allow_partials, description, kind, ...) are SQLMesh's own semantics and stay dialect-agnostic. Deriving it means the policy stays correct as properties are added, and a field that is missed fails safe -- a keyword is not canonicalized, rather than a user's SQL being corrupted. Covers MODEL, AUDIT and METRIC headers, and the expression properties nested inside `kind` such as `time_data_type` and `unique_key`. Signed-off-by: mday-io <mdaytn@gmail.com>
4 tasks
mday-io
pushed a commit
to mday-io/sqlmesh
that referenced
this pull request
Aug 9, 2026
Cherry-picked from upstream sqlmesh/sqlmesh commit c3ec643 (fix(format): keep MODEL/AUDIT/METRIC header dialect-agnostic (SQLMesh#5773) (SQLMesh#5864)), which this fork's main had not yet synced. Needed as a prerequisite for the follow-up fixes to header property rendering. Meta expressions (MODEL/AUDIT/METRIC) are SQLMesh DDL, not standard SQL, so they must never be transpiled to the target dialect -- e.g. tsql would rewrite a boolean property like `allow_partials TRUE` to `(1 = 1)`. Signed-off-by: mday-io <mdaytn@gmail.com>
mday-io
added a commit
to mday-io/sqlmesh
that referenced
this pull request
Aug 9, 2026
…alect SQLMesh#5864 stopped transpiling MODEL/AUDIT/METRIC headers so that SQLMesh's own boolean properties would survive formatting -- on tsql, `allow_partials TRUE` was being rewritten to `(1 = 1)`, which then fails to parse at all and leaves the model file broken. That fix rendered the entire header generically, including the properties whose values are the user's warehouse SQL. Those lose their dialect: `columns (ts DATETIME2(6))` becomes `TIMESTAMP(6)`, and an audit argument such as `CAST('2024-01-01' AS DATETIME2)` is silently downgraded the same way. Split the header per property instead of per expression. The split is derived from the field declarations themselves: expression-typed fields (columns, audits, signals, partitioned_by, physical_properties, ...) hold warehouse SQL and render with the model dialect, while scalar-typed fields (allow_partials, description, kind, ...) are SQLMesh's own semantics and stay dialect-agnostic. Deriving it means the policy stays correct as properties are added, and a field that is missed fails safe -- a keyword is not canonicalized, rather than a user's SQL being corrupted. Covers MODEL, AUDIT and METRIC headers, and the expression properties nested inside `kind` such as `time_data_type` and `unique_key`. Signed-off-by: mday-io <mdaytn@gmail.com>
mday-io
added a commit
to mday-io/sqlmesh
that referenced
this pull request
Aug 9, 2026
…alect SQLMesh#5864 stopped transpiling MODEL/AUDIT/METRIC headers so that SQLMesh's own boolean properties would survive formatting -- on tsql, `allow_partials TRUE` was being rewritten to `(1 = 1)`, which then fails to parse at all and leaves the model file broken. That fix rendered the entire header generically, including the properties whose values are the user's warehouse SQL. Those lose their dialect: `columns (ts DATETIME2(6))` becomes `TIMESTAMP(6)`, and an audit argument such as `CAST('2024-01-01' AS DATETIME2)` is silently downgraded the same way. Split the header per property instead of per expression. The split is derived from the field declarations themselves: expression-typed fields (columns, audits, signals, partitioned_by, physical_properties, ...) hold warehouse SQL and render with the model dialect, while scalar-typed fields (allow_partials, description, kind, ...) are SQLMesh's own semantics and stay dialect-agnostic. Deriving it means the policy stays correct as properties are added, and a field that is missed fails safe -- a keyword is not canonicalized, rather than a user's SQL being corrupted. Covers MODEL, AUDIT and METRIC headers, and the expression properties nested inside `kind` such as `time_data_type` and `unique_key`. Signed-off-by: mday-io <mdaytn@gmail.com>
mday-io
added a commit
to mday-io/sqlmesh
that referenced
this pull request
Aug 9, 2026
…alect SQLMesh#5864 stopped transpiling MODEL/AUDIT/METRIC headers so that SQLMesh's own boolean properties would survive formatting -- on tsql, `allow_partials TRUE` was being rewritten to `(1 = 1)`, which then fails to parse at all and leaves the model file broken. That fix rendered the entire header generically, including the properties whose values are the user's warehouse SQL. Those lose their dialect: `columns (ts DATETIME2(6))` becomes `TIMESTAMP(6)`, and an audit argument such as `CAST('2024-01-01' AS DATETIME2)` is silently downgraded the same way. Split the header per property instead of per expression. The split is derived from the field declarations themselves: expression-typed fields (columns, audits, signals, partitioned_by, physical_properties, ...) hold warehouse SQL and render with the model dialect, while scalar-typed fields (allow_partials, description, kind, ...) are SQLMesh's own semantics and stay dialect-agnostic. Deriving it means the policy stays correct as properties are added, and a field that is missed fails safe -- a keyword is not canonicalized, rather than a user's SQL being corrupted. Covers MODEL, AUDIT and METRIC headers, and the expression properties nested inside `kind` such as `time_data_type` and `unique_key`. Signed-off-by: mday-io <mdaytn@gmail.com>
4 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
sqlmesh formatcorrupts boolean properties in theMODEL (...)header when the model dialect has no nativeTRUEkeyword. On a T-SQL model, a property such asallow_partials trueis rewritten toallow_partials (1 = 1), and SQLMesh can no longer re-parse that as a boolean, so the model file breaks. Fixes #5773.Root cause:
format_model_expressions(sqlmesh/core/dialect.py) rendered every parsed expression with the target dialect, including the SQLMesh-specificMODEL/AUDIT/METRICheader. That header is SQLMesh DDL, not standard SQL, so SQLGlot's tsql generator transpiles a boolean to(1 = 1).This renders meta expressions (
is_meta_expression->Audit/Metric/Model) withdialect=Noneon both the single-meta early return and the multi-expression join path, so the header stays exactly as written, while the actual query/statement body still transpiles to the target dialect.Test Plan
tests/core/test_dialect.py::test_format_model_expressionsasserting the MODEL header keepsallow_partials TRUE(not(1 = 1)) while the query body still transpiles (SELECT TRUE->1,CAST(x AS INT)->x::INTEGER).mainand passes with this change.pytest tests/core/test_dialect.py tests/core/test_format.pygreen;make style(ruff + mypy) clean on both files.AUDIT/METRICheaders share the identicalis_meta_expressioncode path and behave the same; happy to add an AUDIT assertion too if that would be useful.Checklist
make styleand fixed any issuesmake fast-test)git commit -s) per the DCO