Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CT-3267] [Feature] Debug log when type_code fails to convert to a data_type #39

Merged
merged 15 commits into from
Apr 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading