fix(format): keep MODEL/AUDIT/METRIC header dialect-agnostic (#5773)#5864
Open
anxkhn wants to merge 1 commit into
Open
fix(format): keep MODEL/AUDIT/METRIC header dialect-agnostic (#5773)#5864anxkhn wants to merge 1 commit into
anxkhn wants to merge 1 commit into
Conversation
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>
f6078cd to
5fc0cf8
Compare
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