Repository navigation
Conversation
Session parameters such as TIMEZONE or QUERY_TAG are keywords, not identifiers, so Snowflake rejects them when quoted. sqlglot parses them as identifiers, which means model pre/post statements like ALTER SESSION SET TIMEZONE = 'UTC' were rendered and executed as ALTER SESSION SET "TIMEZONE" = 'UTC', a syntax error. Parse unquoted parameter names in ALTER SESSION SET/UNSET as vars so they are neither normalized nor quoted. Fixes SQLMesh#5666 Signed-off-by: Dhruv Gupta <dg@usesparx.com>
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
Fixes #5666.
Snowflake session parameters (
TIMEZONE,QUERY_TAG, ...) are keywords, not identifiers, soALTER SESSION SET "TIMEZONE" = 'UTC'is a syntax error. sqlglot parses the parameter names inALTER SESSION SET/UNSETas identifiers (Column(Identifier)/Identifier), so a model pre/post statement such aswas quoted twice: once by the renderer's normalize-and-quote step and again by
EngineAdapter._to_sql. It reached Snowflake asALTER SESSION SET "TIMEZONE" = 'UTC'.This adds a small parser override in
sqlmesh/core/dialect.py, following the same pattern as the existing T-SQLALTER COLUMNoverride. After sqlglot parsesALTER SESSION, unquoted parameter names becomeexp.Var, so they are neither normalized nor quoted. Values are left alone (literals, macros such as@tag, etc.), and so are parameter names the user quoted explicitly.The SQL produced for the unrendered statement doesn't change (
TIMEZONE = 'UTC'both before and after), so model data and metadata hashes stay the same and existing snapshots aren't affected. I checked this on a sample model.An earlier attempt (#5670) turned quoting off for every
Alter/Setstatement in the Snowflake adapter and also special-cased the renderer. Its author closed it. This change only touchesALTER SESSIONparameter names and lives at the parse level, so the renderer and the engine adapter both pick it up without engine-specific code in either.Test Plan
tests/core/test_dialect.py::test_snowflake_alter_session_parameters_are_not_quoted: parse/generate withidentify=Truefor SET (with a macro value), UNSET, and an explicitly quoted name, plus rendered model pre/post statements.tests/core/engine_adapter/test_snowflake.py::test_alter_session_parameters_are_not_quoted: SQL executed by the mocked Snowflake adapter.main(ALTER SESSION SET "TIMEZONE" = 'UTC') and pass with the fix.pytest -n 8 -m "fast and not web and not github and not dbt and not jupyter and not cicdonly and not isolated": 2436 passed. 6 failures intests/core/test_connection_config.py(pyodbc) are unrelated and come from a missing local unixODBC library; they fail the same way onmain.pytest -m "dbt and fast" tests/dbt: 88 passed.SKIP=prettier,eslint pre-commit run --all-files(ruff, ruff-format, mypy, migrations): passed. The prettier/eslint hooks were skipped because no frontend files changed.Checklist
make styleand fixed any issuesmake fast-test) (I ran the core fast and dbt fast subsets listed above, not the whole target)git commit -s) per the DCO