diff --git a/.changes/unreleased/Under the Hood-20240312-132326.yaml b/.changes/unreleased/Under the Hood-20240312-132326.yaml new file mode 100644 index 00000000..3bdc8f20 --- /dev/null +++ b/.changes/unreleased/Under the Hood-20240312-132326.yaml @@ -0,0 +1,7 @@ +kind: Under the Hood +body: Migrate to dbt-common and dbt-adapters package +time: 2024-03-12T13:23:26.028488+01:00 +custom: + Author: damian3031 + Issue: "387" + PR: "390" diff --git a/dbt/adapters/trino/column.py b/dbt/adapters/trino/column.py index 41c32fb1..0b6b5b79 100644 --- a/dbt/adapters/trino/column.py +++ b/dbt/adapters/trino/column.py @@ -3,7 +3,7 @@ from typing import ClassVar, Dict from dbt.adapters.base.column import Column -from dbt.exceptions import DbtRuntimeError +from dbt_common.exceptions import DbtRuntimeError # Taken from the MAX_LENGTH variable in # https://github.com/trinodb/trino/blob/master/core/trino-spi/src/main/java/io/trino/spi/type/VarcharType.java diff --git a/dbt/adapters/trino/connections.py b/dbt/adapters/trino/connections.py index f40b29b4..28b0e432 100644 --- a/dbt/adapters/trino/connections.py +++ b/dbt/adapters/trino/connections.py @@ -10,12 +10,12 @@ import sqlparse import trino -from dbt.adapters.base import Credentials +from dbt.adapters.contracts.connection import AdapterResponse, Credentials +from dbt.adapters.events.logging import AdapterLogger +from dbt.adapters.exceptions.connection import FailedToConnectError from dbt.adapters.sql import SQLConnectionManager -from dbt.contracts.connection import AdapterResponse -from dbt.events import AdapterLogger -from dbt.exceptions import DbtDatabaseError, DbtRuntimeError, FailedToConnectError -from dbt.helper_types import Port +from dbt_common.exceptions import DbtDatabaseError, DbtRuntimeError +from dbt_common.helper_types import Port from trino.transaction import IsolationLevel from dbt.adapters.trino.__version__ import version diff --git a/dbt/adapters/trino/impl.py b/dbt/adapters/trino/impl.py index 704baf98..3da0265b 100644 --- a/dbt/adapters/trino/impl.py +++ b/dbt/adapters/trino/impl.py @@ -10,8 +10,8 @@ Support, ) from dbt.adapters.sql import SQLAdapter -from dbt.contracts.graph.nodes import ConstraintType -from dbt.exceptions import DbtDatabaseError +from dbt_common.contracts.constraints import ConstraintType +from dbt_common.exceptions import DbtDatabaseError from dbt.adapters.trino import TrinoColumn, TrinoConnectionManager, TrinoRelation diff --git a/dbt/adapters/trino/relation.py b/dbt/adapters/trino/relation.py index 3c322417..a6eea946 100644 --- a/dbt/adapters/trino/relation.py +++ b/dbt/adapters/trino/relation.py @@ -1,7 +1,7 @@ from dataclasses import dataclass, field from dbt.adapters.base.relation import BaseRelation, Policy -from dbt.contracts.relation import ComponentName +from dbt.adapters.contracts.relation import ComponentName @dataclass(frozen=True, eq=False, repr=False) diff --git a/dev_requirements.txt b/dev_requirements.txt index c509b2a4..06551ea1 100644 --- a/dev_requirements.txt +++ b/dev_requirements.txt @@ -1,4 +1,5 @@ -dbt-tests-adapter~=1.7.9 +dbt-core~=1.8.0b1 +dbt-tests-adapter~=1.8.0b1 mypy==1.8.0 # patch updates have historically introduced breaking changes pre-commit~=3.6 pytest~=7.4 diff --git a/setup.py b/setup.py index b744008a..dcd564a3 100644 --- a/setup.py +++ b/setup.py @@ -50,17 +50,8 @@ def _dbt_trino_version(): return trino_version -# require a compatible minor version (~=), prerelease if this is a prerelease -def _get_dbt_core_version(): - parts = _get_plugin_version_dict() - minor = "{major}.{minor}.0".format(**parts) - pre = parts["prekind"] + "1" if parts["prekind"] else "" - return f"{minor}{pre}" - - package_version = _dbt_trino_version() description = """The trino adapter plugin for dbt (data build tool)""" -dbt_version = _get_dbt_core_version() setup( name=package_name, @@ -85,7 +76,8 @@ def _get_dbt_core_version(): ] }, install_requires=[ - "dbt-core~={}".format(dbt_version), + "dbt-common>=1.0.0b1,<2.0", + "dbt-adapters>=1.0.0b1,<2.0", "trino~=0.326", ], zip_safe=False, diff --git a/tests/functional/adapter/show/test_show.py b/tests/functional/adapter/show/test_show.py index 97270b46..67e9b98f 100644 --- a/tests/functional/adapter/show/test_show.py +++ b/tests/functional/adapter/show/test_show.py @@ -1,7 +1,6 @@ import pytest -from dbt.exceptions import DbtRuntimeError -from dbt.exceptions import Exception as DbtException from dbt.tests.util import run_dbt, run_dbt_and_capture +from dbt_common.exceptions import DbtBaseException, DbtRuntimeError from tests.functional.adapter.show.fixtures import ( models__ephemeral_model, @@ -73,7 +72,7 @@ def test_inline_pass(self, project): assert "sample_bool" in log_output def test_inline_fail(self, project): - with pytest.raises(DbtException, match="Error parsing inline query"): + with pytest.raises(DbtBaseException, match="Error parsing inline query"): run_dbt(["show", "--inline", "select * from {{ ref('third_model') }}"]) def test_inline_fail_database_error(self, project): diff --git a/tests/unit/test_adapter.py b/tests/unit/test_adapter.py index 1121065b..d3f2de58 100644 --- a/tests/unit/test_adapter.py +++ b/tests/unit/test_adapter.py @@ -1,13 +1,15 @@ import string import unittest +from multiprocessing import get_context from unittest import TestCase from unittest.mock import MagicMock, Mock, patch import agate import dbt.flags as flags import trino -from dbt.clients import agate_helper -from dbt.exceptions import DbtDatabaseError, DbtRuntimeError, FailedToConnectError +from dbt.adapters.exceptions.connection import FailedToConnectError +from dbt_common.clients import agate_helper +from dbt_common.exceptions import DbtDatabaseError, DbtRuntimeError from dbt.adapters.trino import TrinoAdapter from dbt.adapters.trino.column import TRINO_VARCHAR_MAX_LENGTH, TrinoColumn @@ -70,7 +72,7 @@ def setUp(self): @property def adapter(self): - self._adapter = TrinoAdapter(self.config) + self._adapter = TrinoAdapter(self.config, get_context("spawn")) return self._adapter def test_acquire_connection(self): @@ -144,7 +146,7 @@ def acquire_connection_with_profile(self, profile): config = config_from_parts_or_dicts(project_cfg, profile_cfg) - return TrinoAdapter(config).acquire_connection("dummy") + return TrinoAdapter(config, get_context("spawn")).acquire_connection("dummy") def assert_default_connection_credentials(self, credentials): self.assertEqual(credentials.type, "trino") @@ -447,7 +449,7 @@ def setup_profile(self, credentials): } config = config_from_parts_or_dicts(project_cfg, profile_cfg) - adapter = TrinoAdapter(config) + adapter = TrinoAdapter(config, get_context("spawn")) connection = adapter.acquire_connection("dummy") return connection @@ -501,8 +503,6 @@ def test_true(self): class TestAdapterConversions(TestCase): def _get_tester_for(self, column_type): - from dbt.clients import agate_helper - if column_type is agate.TimeDelta: # dbt never makes this! return agate.TimeDelta() diff --git a/tests/unit/utils.py b/tests/unit/utils.py index 6bb17e16..768a2235 100644 --- a/tests/unit/utils.py +++ b/tests/unit/utils.py @@ -7,7 +7,7 @@ from unittest import TestCase, mock from dbt.config.project import PartialProject -from dbt.dataclass_schema import ValidationError +from dbt_common.dataclass_schema import ValidationError def normalize(path):