-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Handle unknown
type_code
for model contracts (#8887)
* Handle unknown `type_code` for model contracts * Changelog entry * Fix changelog entry * Functional test for a `type_code` that is not recognized by psycopg2 * Functional tests for data type mismatches
- Loading branch information
Showing
3 changed files
with
86 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
kind: Fixes | ||
body: Handle unknown `type_code` for model contracts | ||
time: 2023-10-24T11:01:51.980781-06:00 | ||
custom: | ||
Author: dbeatty10 | ||
Issue: 8877 8353 |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import pytest | ||
from dbt.tests.util import run_dbt, run_dbt_and_capture | ||
|
||
|
||
my_numeric_model_sql = """ | ||
select | ||
12.34 as price | ||
""" | ||
|
||
my_money_model_sql = """ | ||
select | ||
cast('12.34' as money) as price | ||
""" | ||
|
||
model_schema_money_yml = """ | ||
models: | ||
- name: my_model | ||
config: | ||
contract: | ||
enforced: true | ||
columns: | ||
- name: price | ||
data_type: money | ||
""" | ||
|
||
model_schema_numeric_yml = """ | ||
models: | ||
- name: my_model | ||
config: | ||
contract: | ||
enforced: true | ||
columns: | ||
- name: price | ||
data_type: numeric | ||
""" | ||
|
||
|
||
class TestModelContractUnrecognizedTypeCode1: | ||
@pytest.fixture(scope="class") | ||
def models(self): | ||
return { | ||
"my_model.sql": my_money_model_sql, | ||
"schema.yml": model_schema_money_yml, | ||
} | ||
|
||
def test_nonstandard_data_type(self, project): | ||
run_dbt(["run"], expect_pass=True) | ||
|
||
|
||
class TestModelContractUnrecognizedTypeCodeActualMismatch: | ||
@pytest.fixture(scope="class") | ||
def models(self): | ||
return { | ||
"my_model.sql": my_money_model_sql, | ||
"schema.yml": model_schema_numeric_yml, | ||
} | ||
|
||
def test_nonstandard_data_type(self, project): | ||
expected_msg = "unknown type_code 790 | DECIMAL | data type mismatch" | ||
_, logs = run_dbt_and_capture(["run"], expect_pass=False) | ||
assert expected_msg in logs | ||
|
||
|
||
class TestModelContractUnrecognizedTypeCodeExpectedMismatch: | ||
@pytest.fixture(scope="class") | ||
def models(self): | ||
return { | ||
"my_model.sql": my_numeric_model_sql, | ||
"schema.yml": model_schema_money_yml, | ||
} | ||
|
||
def test_nonstandard_data_type(self, project): | ||
expected_msg = "DECIMAL | unknown type_code 790 | data type mismatch" | ||
_, logs = run_dbt_and_capture(["run"], expect_pass=False) | ||
print(logs) | ||
assert expected_msg in logs |