diff --git a/.changes/unreleased/Features-20240323-160222.yaml b/.changes/unreleased/Features-20240323-160222.yaml new file mode 100644 index 00000000..c5af1aca --- /dev/null +++ b/.changes/unreleased/Features-20240323-160222.yaml @@ -0,0 +1,6 @@ +kind: Features +body: Debug log when `type_code` fails to convert to a `data_type` +time: 2024-03-23T16:02:22.153674-06:00 +custom: + Author: dbeatty10 + Issue: "8912" diff --git a/dbt/adapters/postgres/connections.py b/dbt/adapters/postgres/connections.py index 741f5701..83f26957 100644 --- a/dbt/adapters/postgres/connections.py +++ b/dbt/adapters/postgres/connections.py @@ -4,8 +4,10 @@ from dbt.adapters.contracts.connection import AdapterResponse, Credentials from dbt.adapters.events.logging import AdapterLogger +from dbt.adapters.events.types import TypeCodeNotFound from dbt.adapters.sql import SQLConnectionManager from dbt_common.exceptions import DbtDatabaseError, DbtRuntimeError +from dbt_common.events.functions import warn_or_error from dbt_common.helper_types import Port from mashumaro.jsonschema.annotations import Maximum, Minimum import psycopg2 @@ -203,4 +205,5 @@ def data_type_code_to_name(cls, type_code: Union[int, str]) -> str: if type_code in psycopg2.extensions.string_types: return psycopg2.extensions.string_types[type_code].name else: + warn_or_error(TypeCodeNotFound(type_code=type_code)) return f"unknown type_code {type_code}" diff --git a/tests/functional/contracts/test_nonstandard_data_type.py b/tests/functional/contracts/test_nonstandard_data_type.py index ee48bb3c..e563f4d1 100644 --- a/tests/functional/contracts/test_nonstandard_data_type.py +++ b/tests/functional/contracts/test_nonstandard_data_type.py @@ -1,6 +1,6 @@ import pytest -from tests.functional.utils import run_dbt, run_dbt_and_capture +from tests.functional.utils import run_dbt_and_capture my_numeric_model_sql = """ @@ -45,7 +45,9 @@ def models(self): } def test_nonstandard_data_type(self, project): - run_dbt(["run"], expect_pass=True) + expected_debug_msg = "The `type_code` 790 was not recognized" + _, logs = run_dbt_and_capture(["--debug", "run"], expect_pass=True) + assert expected_debug_msg in logs class TestModelContractUnrecognizedTypeCodeActualMismatch: @@ -58,8 +60,10 @@ def models(self): 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) + expected_debug_msg = "The `type_code` 790 was not recognized" + _, logs = run_dbt_and_capture(["--debug", "run"], expect_pass=False) assert expected_msg in logs + assert expected_debug_msg in logs class TestModelContractUnrecognizedTypeCodeExpectedMismatch: @@ -72,6 +76,7 @@ def models(self): 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) + expected_debug_msg = "The `type_code` 790 was not recognized" + _, logs = run_dbt_and_capture(["--debug", "run"], expect_pass=False) assert expected_msg in logs + assert expected_debug_msg in logs