Skip to content

Commit

Permalink
[CT-3267] [Feature] Debug log when type_code fails to convert to a …
Browse files Browse the repository at this point in the history
…`data_type` (#39)

Co-authored-by: Mike Alfare <13974384+mikealfare@users.noreply.github.com>
Co-authored-by: colin-rogers-dbt <111200756+colin-rogers-dbt@users.noreply.github.com>
Co-authored-by: Mike Alfare <mike.alfare@dbtlabs.com>
  • Loading branch information
4 people committed Apr 19, 2024
1 parent 333a1e5 commit 118fbbd
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
6 changes: 6 additions & 0 deletions .changes/unreleased/Features-20240323-160222.yaml
Original file line number Diff line number Diff line change
@@ -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"
3 changes: 3 additions & 0 deletions dbt/adapters/postgres/connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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}"
15 changes: 10 additions & 5 deletions tests/functional/contracts/test_nonstandard_data_type.py
Original file line number Diff line number Diff line change
@@ -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 = """
Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand All @@ -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

0 comments on commit 118fbbd

Please sign in to comment.