Empty unit test fixtures (rows: []) emit invalid LIMIT 0 syntax#699
Merged
Conversation
Chore/version v1.10.0rc1
…698) dbt-core's get_fixture_sql/get_expected_sql hardcode `limit 0` for empty fixture rows, which is not valid T-SQL. These macros are not dispatched, so shadow them in the adapter package and emit `select top 0` instead. get_expected_sql's empty branch builds typed nulls rather than selecting from dbt_internal_unit_test_actual, which is out of scope inside the view created by sqlserver__get_unit_test_sql. Also fix sqlserver__get_columns_in_query for queries starting with a CTE (hit by unit tests with an empty `expect` block): such queries cannot be wrapped in a subquery, so describe their result set via sp_describe_first_result_set instead of executing them. Non-CTE queries keep the existing TOP 0 wrapping. The CTE detection is factored into a shared sqlserver__select_starts_with_cte helper. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
axellpadilla
requested changes
Jun 4, 2026
Collaborator
|
Referencing issue dbt-labs/dbt-adapters#2021 |
…erver__ implementations The shadowed public macros (get_fixture_sql, get_expected_sql) are now thin wrappers that delegate to sqlserver__get_fixture_sql / sqlserver__get_expected_sql, which contain the copied/adapted upstream logic with T-SQL-specific changes (select top 0 instead of limit 0). If dbt-core later adds adapter.dispatch for these macros, this adapter can delete the public wrappers and keep the sqlserver__ implementations as the dispatched handlers.
axellpadilla
approved these changes
Jun 14, 2026
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.
Fixes #698
dbt-core hardcodes
limit 0for empty fixture rows, which is not valid T-SQL. These macros are not dispatched, so shadow them in the adapter package and emitselect top 0instead.Also fix sqlserver__get_columns_in_query for queries starting with a CTE (hit by unit tests with an empty
expectblock): such queries cannot be wrapped in a subquery, so describe their result set via sp_describe_first_result_set instead of executing them. Non-CTE queries keep the existing TOP 0 wrapping. The CTE detection is factored into a shared sqlserver__select_starts_with_cte helper.