Skip to content

Bug: rows: [] in unit test given block emits LIMIT 0 #698

@Benjamin-Knight

Description

@Benjamin-Knight

Adapter: dbt-sqlserver 1.10.0-rc1
dbt Core: 1.10.20
SQL Server: Microsoft ODBC Driver 18

Description

When a unit test given block specifies rows: [] for an input, dbt core generates an
empty-fixture CTE of the form:

__dbt__cte__some_ref as (
    -- Fixture for some_ref
    select try_cast(null as varchar(255)) as "col_a"
    limit 0
)

The query fails immediately with:

('42000', "[42000] [Microsoft][ODBC Driver 18 for SQL Server][SQL Server]
Incorrect syntax near 'limit'. (102) (SQLMoreResults)")

Steps to reproduce

  1. Define a dbt unit test where at least one given input has rows: [].
  2. Run dbt test --resource-type unit_test.

Minimal YAML excerpt:

unit_tests:
  - name: my_test
    model: my_model
    given:
      - input: ref('some_ref')
        rows: []          # <-- triggers the bug
      - input: ref('other_ref')
        rows:
          - col_a: 'foo'
    expect:
      rows:
        - col_a: 'foo'

Expected behaviour

An empty rows: [] block should produce a zero-row CTE using T-SQL-compatible
syntax

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No fields configured for Bug.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions