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 12 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"
5 changes: 5 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,7 @@ 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(
mikealfare marked this conversation as resolved.
Show resolved Hide resolved
TypeCodeNotFound(type_code=type_code)
)
return f"unknown type_code {type_code}"
2 changes: 1 addition & 1 deletion hatch_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

BASE_DEPS = [
# psycopg2 dependency installed in custom hatch_build.py
"dbt-adapters>=0.1.0a1,<2.0",
"dbt-adapters @ git+https://github.com/dbt-labs/dbt-adapters.git@dbeatty/unknown-data-type-code-8912",
dbeatty10 marked this conversation as resolved.
Show resolved Hide resolved
# add dbt-core to ensure backwards compatibility of installation, this is not a functional dependency
"dbt-core>=1.8.0a1",
# installed via dbt-adapters but used directly
Expand Down
10 changes: 5 additions & 5 deletions pyproject.toml
dbeatty10 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ path = "./hatch_build.py"

[tool.hatch.envs.default]
dependencies = [
"dbt-adapters @ git+https://github.com/dbt-labs/dbt-adapters.git",
"dbt-adapters @ git+https://github.com/dbt-labs/dbt-adapters.git@dbeatty/unknown-data-type-code-8912",
"dbt-common @ git+https://github.com/dbt-labs/dbt-common.git",
]

Expand Down Expand Up @@ -86,7 +86,7 @@ dependencies = [
]
extra-dependencies = [
# TODO: remove `dbt-core` dependencies from unit tests
"dbt-adapters @ git+https://github.com/dbt-labs/dbt-adapters.git",
"dbt-adapters @ git+https://github.com/dbt-labs/dbt-adapters.git@dbeatty/unknown-data-type-code-8912",
"dbt-common @ git+https://github.com/dbt-labs/dbt-common.git",
"dbt-core @ git+https://github.com/dbt-labs/dbt-core.git#subdirectory=core",
]
Expand All @@ -97,10 +97,10 @@ all = "python -m pytest {args:tests/unit}"
template = "unit-tests"
extra-dependencies = [
# TODO: remove `dbt-core` dependencies from integration tests
"dbt-adapters @ git+https://github.com/dbt-labs/dbt-adapters.git",
"dbt-adapters @ git+https://github.com/dbt-labs/dbt-adapters.git@dbeatty/unknown-data-type-code-8912",
"dbt-common @ git+https://github.com/dbt-labs/dbt-common.git",
"dbt-core @ git+https://github.com/dbt-labs/dbt-core.git#subdirectory=core",
"dbt-tests-adapter @ git+https://github.com/dbt-labs/dbt-adapters.git#subdirectory=dbt-tests-adapter",
"dbt-tests-adapter @ git+https://github.com/dbt-labs/dbt-adapters.git@dbeatty/unknown-data-type-code-8912#subdirectory=dbt-tests-adapter",
]
[tool.hatch.envs.integration-tests.env-vars]
DBT_TEST_USER_1 = "dbt_test_user_1"
Expand Down Expand Up @@ -165,4 +165,4 @@ env_files = ["test.env"]
testpaths = [
"tests/functional",
"tests/unit",
]
]
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