Skip to content

fix: quote openquery's server name via adapter.quote() instead of hand-formatted brackets - #816

Merged
axellpadilla merged 1 commit into
masterfrom
fix/openquery-hand-formatted-identifier-quoting
Aug 7, 2026
Merged

fix: quote openquery's server name via adapter.quote() instead of hand-formatted brackets#816
axellpadilla merged 1 commit into
masterfrom
fix/openquery-hand-formatted-identifier-quoting

Conversation

@axellpadilla

Copy link
Copy Markdown
Collaborator

Summary

PR #790 landed sqlserver__openquery emitting OPENQUERY([{{ server_name }}], ...) — a hand-formatted bracket identifier. That trips the #785 guard (test_macros_do_not_hand_format_identifiers), which requires every macro-built identifier to go through adapter.quote() so generated SQL keeps one quoting style, and broke CI on master right after merge:

AssertionError: use adapter.quote() or the relation object so generated SQL keeps one quoting style (#785):
    openquery.sql:20 ([{{ ... }}]): OPENQUERY([{{ server_name }}], '{{ cleaned_sql }}')

Fix

  • OPENQUERY([{{ server_name }}], ...)OPENQUERY({{ adapter.quote(server_name) }}, ...). SQL Server accepts a double-quoted linked-server name under QUOTED_IDENTIFIER ON, the adapter's default.
  • Updated tests/functional/adapter/mssql/test_openquery.py's compiled-SQL assertions from OPENQUERY([LOCALLOOP], ...) to OPENQUERY("LOCALLOOP", ...).

Test plan

  • pytest tests/unit/adapters/mssql/test_quote.py — 60 passed, including the previously-failing test_macros_do_not_hand_format_identifiers[openquery.sql]
  • pytest tests/unit — 500 passed
  • ruff check dbt/ tests/ — clean
  • pytest tests/functional/adapter/mssql/test_openquery.py against a live local SQL Server (loopback linked server) — 9 passed
  • pre-commit (ruff, ty) passed on commit

… hand-formatted brackets

sqlserver__openquery emitted OPENQUERY([{{ server_name }}], ...), a hand-
formatted bracket identifier that bypasses adapter.quote() and breaks the
one-quoting-style guard from #785 (test_macros_do_not_hand_format_identifiers).
Route it through adapter.quote() like every other macro-built identifier;
SQL Server accepts a double-quoted linked-server name under QUOTED_IDENTIFIER
ON (the adapter's default). Updates the functional test's compiled-SQL
assertions to match the new quoting.
@axellpadilla
axellpadilla enabled auto-merge August 6, 2026 23:56
@axellpadilla
axellpadilla merged commit be7e0f4 into master Aug 7, 2026
6 of 20 checks passed
@axellpadilla
axellpadilla deleted the fix/openquery-hand-formatted-identifier-quoting branch August 7, 2026 00:57
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.

1 participant