Skip to content

fix(snowflake): do not quote parameter names in ALTER SESSION - #6122

Open
DG47 wants to merge 1 commit into
SQLMesh:mainfrom
DG47:fix/snowflake-alter-session-quoting
Open

DG47 wants to merge 1 commit into
SQLMesh:mainfrom
DG47:fix/snowflake-alter-session-quoting

Conversation

@DG47

@DG47 DG47 commented Oct 8, 2026

Copy link
Copy Markdown

Description

Fixes #5666.

Snowflake session parameters (TIMEZONE, QUERY_TAG, ...) are keywords, not identifiers, so ALTER SESSION SET "TIMEZONE" = 'UTC' is a syntax error. sqlglot parses the parameter names in ALTER SESSION SET/UNSET as identifiers (Column(Identifier) / Identifier), so a model pre/post statement such as

ALTER SESSION SET TIMEZONE = 'UTC';

was quoted twice: once by the renderer's normalize-and-quote step and again by EngineAdapter._to_sql. It reached Snowflake as ALTER SESSION SET "TIMEZONE" = 'UTC'.

This adds a small parser override in sqlmesh/core/dialect.py, following the same pattern as the existing T-SQL ALTER COLUMN override. After sqlglot parses ALTER SESSION, unquoted parameter names become exp.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/Set statement in the Snowflake adapter and also special-cased the renderer. Its author closed it. This change only touches ALTER SESSION parameter 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 with identify=True for 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.
  • Both tests fail on 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 in tests/core/test_connection_config.py (pyodbc) are unrelated and come from a missing local unixODBC library; they fail the same way on main.
  • 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

  • I have run make style and fixed any issues
  • I have added tests for my changes (if applicable)
  • All existing tests pass (make fast-test) (I ran the core fast and dbt fast subsets listed above, not the whole target)
  • My commits are signed off (git commit -s) per the DCO

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

quoting parameters in ALTER SESSION SET for Snowflake is illegal syntax.

1 participant