Skip to content

Commit

Permalink
Remove usage of dbt.contracts.relation in dbt/adapters (#9207)
Browse files Browse the repository at this point in the history
  • Loading branch information
MichelleArk authored Dec 6, 2023
1 parent 00f4920 commit e01eb30
Show file tree
Hide file tree
Showing 15 changed files with 43 additions and 35 deletions.
6 changes: 6 additions & 0 deletions .changes/unreleased/Under the Hood-20231205-120559.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
kind: Under the Hood
body: Remove usage of dbt.contracts in dbt/adapters
time: 2023-12-05T12:05:59.936775+09:00
custom:
Author: michelleark
Issue: "9208"
2 changes: 1 addition & 1 deletion core/dbt/adapters/base/relation.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from typing import Optional, TypeVar, Any, Type, Dict, Iterator, Tuple, Set, Union, FrozenSet

from dbt.contracts.graph.nodes import SourceDefinition, ManifestNode, ResultNode, ParsedNode
from dbt.contracts.relation import (
from dbt.adapters.contracts.relation import (
RelationType,
ComponentName,
HasQuoting,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@

from dbt.common.dataclass_schema import dbtClassMixin, StrEnum

from dbt.contracts.util import Replaceable
from dbt.common.exceptions import CompilationError
from dbt.exceptions import DataclassNotDictError
from dbt.common.contracts.util import Replaceable
from dbt.common.exceptions import CompilationError, DataclassNotDictError
from dbt.common.utils import deep_merge


Expand Down
2 changes: 1 addition & 1 deletion core/dbt/adapters/protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
import agate

from dbt.adapters.contracts.connection import Connection, AdapterRequiredConfig, AdapterResponse
from dbt.adapters.contracts.relation import Policy, HasQuoting
from dbt.contracts.graph.nodes import ResultNode
from dbt.contracts.graph.model_config import BaseConfig
from dbt.contracts.graph.manifest import Manifest
from dbt.contracts.relation import Policy, HasQuoting


@dataclass
Expand Down
1 change: 1 addition & 0 deletions core/dbt/common/exceptions/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from dbt.common.exceptions.base import * # noqa
from dbt.common.exceptions.events import * # noqa
from dbt.common.exceptions.macros import * # noqa
from dbt.common.exceptions.contracts import * # noqa
17 changes: 17 additions & 0 deletions core/dbt/common/exceptions/contracts.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from typing import Any
from dbt.common.exceptions import CompilationError


# this is part of the context and also raised in dbt.contracts.relation.py
class DataclassNotDictError(CompilationError):
def __init__(self, obj: Any):
self.obj = obj
super().__init__(msg=self.get_message())

Check warning on line 9 in core/dbt/common/exceptions/contracts.py

View check run for this annotation

Codecov / codecov/patch

core/dbt/common/exceptions/contracts.py#L8-L9

Added lines #L8 - L9 were not covered by tests

def get_message(self) -> str:
msg = (

Check warning on line 12 in core/dbt/common/exceptions/contracts.py

View check run for this annotation

Codecov / codecov/patch

core/dbt/common/exceptions/contracts.py#L12

Added line #L12 was not covered by tests
f'The object ("{self.obj}") was used as a dictionary. This '
"capability has been removed from objects of this type."
)

return msg

Check warning on line 17 in core/dbt/common/exceptions/contracts.py

View check run for this annotation

Codecov / codecov/patch

core/dbt/common/exceptions/contracts.py#L17

Added line #L17 was not covered by tests
6 changes: 3 additions & 3 deletions core/dbt/config/runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@
Type,
)

from dbt.flags import get_flags
from dbt.adapters.factory import get_include_paths, get_relation_class_by_name
from dbt.config.project import load_raw_project
from dbt.adapters.contracts.connection import AdapterRequiredConfig, Credentials, HasCredentials
from dbt.adapters.contracts.relation import ComponentName
from dbt.flags import get_flags
from dbt.config.project import load_raw_project
from dbt.contracts.graph.manifest import ManifestMetadata
from dbt.contracts.project import Configuration, UserConfig
from dbt.contracts.relation import ComponentName
from dbt.common.dataclass_schema import ValidationError
from dbt.common.events.functions import warn_or_error
from dbt.common.events.types import UnusedResourceConfigPath
Expand Down
8 changes: 6 additions & 2 deletions core/dbt/context/exceptions_jinja.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@
from dbt.common.events.functions import warn_or_error
from dbt.common.events.types import JinjaLogWarning

from dbt.common.exceptions import DbtRuntimeError, NotImplementedError, DbtDatabaseError
from dbt.common.exceptions import (
DbtRuntimeError,
NotImplementedError,
DbtDatabaseError,
DataclassNotDictError,
)
from dbt.adapters.exceptions import (
MissingConfigError,
ColumnTypeMissingError,
Expand All @@ -15,7 +20,6 @@
MissingRelationError,
AmbiguousAliasError,
AmbiguousCatalogMatchError,
DataclassNotDictError,
CompilationError,
DependencyNotFoundError,
DependencyError,
Expand Down
6 changes: 1 addition & 5 deletions core/dbt/contracts/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
)
from dbt.version import __version__

from dbt.common.contracts.util import Replaceable
from dbt.common.events.functions import get_metadata_vars
from dbt.common.invocation import get_invocation_id
from dbt.common.dataclass_schema import dbtClassMixin
Expand Down Expand Up @@ -41,11 +42,6 @@ class Foo:
return []


class Replaceable:
def replace(self, **kwargs):
return dataclasses.replace(self, **kwargs)


class Mergeable(Replaceable):
def merged(self, *args):
"""Perform a shallow merge, where the last non-None write wins. This is
Expand Down
15 changes: 0 additions & 15 deletions core/dbt/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -1363,21 +1363,6 @@ def get_message(self) -> str:
return msg


# this is part of the context and also raised in dbt.contracts.relation.py
class DataclassNotDictError(CompilationError):
def __init__(self, obj: Any):
self.obj = obj
super().__init__(msg=self.get_message())

def get_message(self) -> str:
msg = (
f'The object ("{self.obj}") was used as a dictionary. This '
"capability has been removed from objects of this type."
)

return msg


class DependencyNotFoundError(CompilationError):
def __init__(self, node, node_description, required_pkg):
self.node = node
Expand Down
2 changes: 1 addition & 1 deletion plugins/postgres/dbt/adapters/postgres/relation.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
RelationResults,
)
from dbt.context.providers import RuntimeConfigObject
from dbt.contracts.relation import RelationType
from dbt.adapters.contracts.relation import RelationType
from dbt.common.exceptions import DbtRuntimeError

from dbt.adapters.postgres.relation_configs import (
Expand Down
2 changes: 1 addition & 1 deletion tests/adapter/dbt/tests/adapter/materialized_view/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import pytest

from dbt.adapters.base.relation import BaseRelation
from dbt.contracts.relation import RelationType
from dbt.adapters.contracts.relation import RelationType
from dbt.tests.util import (
assert_message_in_logs,
get_model_file,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from dbt.adapters.base.relation import BaseRelation
from dbt.contracts.graph.model_config import OnConfigurationChangeOption
from dbt.contracts.relation import RelationType
from dbt.adapters.contracts.relation import RelationType
from dbt.tests.util import (
assert_message_in_logs,
get_model_file,
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_postgres_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from unittest import mock

from dbt.adapters.base import BaseRelation
from dbt.contracts.relation import Path
from dbt.adapters.contracts.relation import Path
from dbt.task.debug import DebugTask

from dbt.adapters.base.query_headers import MacroQueryStringSetter
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_relation.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import pytest

from dbt.adapters.base import BaseRelation
from dbt.contracts.relation import RelationType
from dbt.adapters.contracts.relation import RelationType


@pytest.mark.parametrize(
Expand Down

0 comments on commit e01eb30

Please sign in to comment.