Skip to content

Commit 292d173

Browse files
authored
Fix the unit test materialization so that it finds columns in the quoted column mapping (#1274)
1 parent aed3c2f commit 292d173

File tree

5 files changed

+85
-1
lines changed

5 files changed

+85
-1
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
kind: Fixes
2+
body: Correct column mapping lookup in unit test macro
3+
time: 2025-08-18T17:42:17.687393-05:00
4+
custom:
5+
Author: QMalcolm
6+
Issue: "1273"

dbt-adapters/src/dbt/include/global_project/macros/materializations/tests/unit.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
{%- set expected_column_names_quoted = [] -%}
2121
{%- for column_name in tested_expected_column_names -%}
22-
{%- do expected_column_names_quoted.append(column_name_to_quoted[column_name]) -%}
22+
{%- do expected_column_names_quoted.append(column_name_to_quoted[column_name|lower]) -%}
2323
{%- endfor -%}
2424

2525
{% if not expected_sql %}

dbt-postgres/tests/functional/adapter/test_unit_testing.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
from dbt.tests.adapter.unit_testing.test_case_insensitivity import BaseUnitTestCaseInsensivity
22
from dbt.tests.adapter.unit_testing.test_invalid_input import BaseUnitTestInvalidInput
3+
from dbt.tests.adapter.unit_testing.test_quoted_reserved_word_column_names import (
4+
BaseUnitTestQuotedReservedWordColumnNames,
5+
)
36
from dbt.tests.adapter.unit_testing.test_types import BaseUnitTestingTypes
47

58

@@ -13,3 +16,7 @@ class TestPostgresUnitTestInvalidInput(BaseUnitTestInvalidInput):
1316

1417
class TestPostgresUnitTestingTypes(BaseUnitTestingTypes):
1518
pass
19+
20+
21+
class TestPostgresUnitTestQuotedReservedWordColumnNames(BaseUnitTestQuotedReservedWordColumnNames):
22+
pass
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
kind: Features
2+
body: Add new test for test unit tests involing models with columns with reserved
3+
words
4+
time: 2025-08-18T18:19:37.508909-05:00
5+
custom:
6+
Author: QMalcolm
7+
Issue: "1273"
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import pytest
2+
from dbt.tests.util import run_dbt
3+
4+
5+
my_model_sql = """
6+
select
7+
* from {{ ref('my_upstream_model')}}
8+
"""
9+
10+
my_upstream_model_with_reserved_word_column_name_sql = """
11+
select 1 as "GROUP"
12+
"""
13+
14+
test_my_model_csv_fixtures_yml = """
15+
unit_tests:
16+
- name: test_my_model
17+
model: my_model
18+
given:
19+
- input: ref('my_upstream_model')
20+
format: csv
21+
fixture: input_fixture
22+
expect:
23+
format: csv
24+
fixture: expect_fixture
25+
"""
26+
27+
input_fixture_csv = """
28+
GROUP
29+
1
30+
2
31+
3
32+
"""
33+
34+
expect_fixture_csv = """
35+
GROUP
36+
1
37+
2
38+
3
39+
"""
40+
41+
42+
class BaseUnitTestQuotedReservedWordColumnNames:
43+
@pytest.fixture(scope="class")
44+
def models(self):
45+
return {
46+
"my_model.sql": my_model_sql,
47+
"my_upstream_model.sql": my_upstream_model_with_reserved_word_column_name_sql,
48+
"unit_tests.yml": test_my_model_csv_fixtures_yml,
49+
}
50+
51+
@pytest.fixture(scope="class")
52+
def tests(self):
53+
return {
54+
"fixtures": {
55+
"input_fixture.csv": input_fixture_csv,
56+
"expect_fixture.csv": expect_fixture_csv,
57+
},
58+
}
59+
60+
def test_quoted_reserved_word_column_names(self, project):
61+
results = run_dbt(["run"])
62+
assert len(results) == 2
63+
64+
results = run_dbt(["test"])

0 commit comments

Comments
 (0)