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

Refactor Base Exceptions #8989

Merged
merged 20 commits into from
Nov 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
2474722
moving types_pb2.py to common/events
colin-rogers-dbt Oct 25, 2023
07743b7
merge
colin-rogers-dbt Oct 25, 2023
252e3e3
Merge branch 'feature/decouple-adapters-from-core' of https://github.…
colin-rogers-dbt Oct 26, 2023
ff9d519
Merge branch 'feature/decouple-adapters-from-core' of https://github.…
colin-rogers-dbt Nov 2, 2023
4270ba0
Refactor Base Exceptions
colin-rogers-dbt Nov 2, 2023
5ee9a73
circular madness
colin-rogers-dbt Nov 2, 2023
81230f2
add events.py
colin-rogers-dbt Nov 2, 2023
75ad9bc
update make_log_dir_if_missing to handle str
colin-rogers-dbt Nov 2, 2023
70167dd
fix circular import
MichelleArk Nov 2, 2023
4cff3fb
set --warn-error default to False instead of implicit Falsey via None
MichelleArk Nov 2, 2023
a09d756
move Exception to common exceptions
MichelleArk Nov 2, 2023
8a7bb22
move more exceptions, fix warn-errors flag
colin-rogers-dbt Nov 3, 2023
88b0c9d
move remaining adapters exception imports to common/adapters
colin-rogers-dbt Nov 3, 2023
f88cb03
move remaining adapters exception imports to common/adapters
colin-rogers-dbt Nov 3, 2023
29f6d0d
fix postgres exception imports
MichelleArk Nov 7, 2023
13e85ac
update dbt-postgres
colin-rogers-dbt Nov 7, 2023
0e7ca24
Merge branch 'addNodeProtocol' of https://github.com/dbt-labs/dbt-cor…
colin-rogers-dbt Nov 7, 2023
3c40279
update dbt-postgres
colin-rogers-dbt Nov 7, 2023
dff3153
update dbt-postgres, migrate more exceptions to common/adapters and a…
colin-rogers-dbt Nov 7, 2023
697e469
remove NodeProtocol
colin-rogers-dbt Nov 9, 2023
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-20231107-135635.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
kind: Features
body: Remove legacy logger
time: 2023-11-07T13:56:35.186648-08:00
custom:
Author: colin-rogers-dbt
Issue: "8027"
6 changes: 6 additions & 0 deletions .changes/unreleased/Under the Hood-20231107-135728.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
kind: Under the Hood
body: Remove use of dbt/core exceptions in dbt/adapter
time: 2023-11-07T13:57:28.683727-08:00
custom:
Author: colin-rogers-dbt MichelleArk
Issue: "8920"
2 changes: 1 addition & 1 deletion core/dbt/adapters/base/column.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import re
from typing import Dict, ClassVar, Any, Optional

from dbt.exceptions import DbtRuntimeError
from dbt.common.exceptions import DbtRuntimeError


@dataclass
Expand Down
45 changes: 28 additions & 17 deletions core/dbt/adapters/base/connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@

import agate

import dbt.exceptions
import dbt.adapters.exceptions
import dbt.common.exceptions.base
from dbt.adapters.contracts.connection import (
Connection,
Identifier,
Expand Down Expand Up @@ -91,13 +92,15 @@
key = self.get_thread_identifier()
with self.lock:
if key not in self.thread_connections:
raise dbt.exceptions.InvalidConnectionError(key, list(self.thread_connections))
raise dbt.adapters.exceptions.InvalidConnectionError(
key, list(self.thread_connections)
)
return self.thread_connections[key]

def set_thread_connection(self, conn: Connection) -> None:
key = self.get_thread_identifier()
if key in self.thread_connections:
raise dbt.exceptions.DbtInternalError(
raise dbt.common.exceptions.DbtInternalError(

Check warning on line 103 in core/dbt/adapters/base/connections.py

View check run for this annotation

Codecov / codecov/patch

core/dbt/adapters/base/connections.py#L103

Added line #L103 was not covered by tests
"In set_thread_connection, existing connection exists for {}"
)
self.thread_connections[key] = conn
Expand Down Expand Up @@ -137,7 +140,7 @@
:return: A context manager that handles exceptions raised by the
underlying database.
"""
raise dbt.exceptions.NotImplementedError(
raise dbt.common.exceptions.base.NotImplementedError(

Check warning on line 143 in core/dbt/adapters/base/connections.py

View check run for this annotation

Codecov / codecov/patch

core/dbt/adapters/base/connections.py#L143

Added line #L143 was not covered by tests
"`exception_handler` is not implemented for this adapter!"
)

Expand Down Expand Up @@ -220,22 +223,22 @@
:param int _attempts: Parameter used to keep track of the number of attempts in calling the
connect function across recursive calls. Passed as an argument to retry_timeout if it
is a Callable. This parameter should not be set by the initial caller.
:raises dbt.exceptions.FailedToConnectError: Upon exhausting all retry attempts without
:raises dbt.adapters.exceptions.FailedToConnectError: Upon exhausting all retry attempts without
successfully acquiring a handle.
:return: The given connection with its appropriate state and handle attributes set
depending on whether we successfully acquired a handle or not.
"""
timeout = retry_timeout(_attempts) if callable(retry_timeout) else retry_timeout
if timeout < 0:
raise dbt.exceptions.FailedToConnectError(
raise dbt.adapters.exceptions.FailedToConnectError(
"retry_timeout cannot be negative or return a negative time."
)

if retry_limit < 0 or retry_limit > sys.getrecursionlimit():
# This guard is not perfect others may add to the recursion limit (e.g. built-ins).
connection.handle = None
connection.state = ConnectionState.FAIL
raise dbt.exceptions.FailedToConnectError("retry_limit cannot be negative")
raise dbt.adapters.exceptions.FailedToConnectError("retry_limit cannot be negative")

try:
connection.handle = connect()
Expand All @@ -246,7 +249,7 @@
if retry_limit <= 0:
connection.handle = None
connection.state = ConnectionState.FAIL
raise dbt.exceptions.FailedToConnectError(str(e))
raise dbt.adapters.exceptions.FailedToConnectError(str(e))

logger.debug(
f"Got a retryable error when attempting to open a {cls.TYPE} connection.\n"
Expand All @@ -268,12 +271,12 @@
except Exception as e:
connection.handle = None
connection.state = ConnectionState.FAIL
raise dbt.exceptions.FailedToConnectError(str(e))
raise dbt.adapters.exceptions.FailedToConnectError(str(e))

@abc.abstractmethod
def cancel_open(self) -> Optional[List[str]]:
"""Cancel all open connections on the adapter. (passable)"""
raise dbt.exceptions.NotImplementedError(
raise dbt.common.exceptions.base.NotImplementedError(

Check warning on line 279 in core/dbt/adapters/base/connections.py

View check run for this annotation

Codecov / codecov/patch

core/dbt/adapters/base/connections.py#L279

Added line #L279 was not covered by tests
"`cancel_open` is not implemented for this adapter!"
)

Expand All @@ -288,7 +291,9 @@
This should be thread-safe, or hold the lock if necessary. The given
connection should not be in either in_use or available.
"""
raise dbt.exceptions.NotImplementedError("`open` is not implemented for this adapter!")
raise dbt.common.exceptions.base.NotImplementedError(

Check warning on line 294 in core/dbt/adapters/base/connections.py

View check run for this annotation

Codecov / codecov/patch

core/dbt/adapters/base/connections.py#L294

Added line #L294 was not covered by tests
"`open` is not implemented for this adapter!"
)

def release(self) -> None:
with self.lock:
Expand Down Expand Up @@ -320,12 +325,16 @@
@abc.abstractmethod
def begin(self) -> None:
"""Begin a transaction. (passable)"""
raise dbt.exceptions.NotImplementedError("`begin` is not implemented for this adapter!")
raise dbt.common.exceptions.base.NotImplementedError(

Check warning on line 328 in core/dbt/adapters/base/connections.py

View check run for this annotation

Codecov / codecov/patch

core/dbt/adapters/base/connections.py#L328

Added line #L328 was not covered by tests
"`begin` is not implemented for this adapter!"
)

@abc.abstractmethod
def commit(self) -> None:
"""Commit a transaction. (passable)"""
raise dbt.exceptions.NotImplementedError("`commit` is not implemented for this adapter!")
raise dbt.common.exceptions.base.NotImplementedError(

Check warning on line 335 in core/dbt/adapters/base/connections.py

View check run for this annotation

Codecov / codecov/patch

core/dbt/adapters/base/connections.py#L335

Added line #L335 was not covered by tests
"`commit` is not implemented for this adapter!"
)

@classmethod
def _rollback_handle(cls, connection: Connection) -> None:
Expand Down Expand Up @@ -361,7 +370,7 @@
def _rollback(cls, connection: Connection) -> None:
"""Roll back the given connection."""
if connection.transaction_open is False:
raise dbt.exceptions.DbtInternalError(
raise dbt.common.exceptions.DbtInternalError(

Check warning on line 373 in core/dbt/adapters/base/connections.py

View check run for this annotation

Codecov / codecov/patch

core/dbt/adapters/base/connections.py#L373

Added line #L373 was not covered by tests
f"Tried to rollback transaction on connection "
f'"{connection.name}", but it does not have one open!'
)
Expand Down Expand Up @@ -412,7 +421,9 @@
:return: A tuple of the query status and results (empty if fetch=False).
:rtype: Tuple[AdapterResponse, agate.Table]
"""
raise dbt.exceptions.NotImplementedError("`execute` is not implemented for this adapter!")
raise dbt.common.exceptions.base.NotImplementedError(

Check warning on line 424 in core/dbt/adapters/base/connections.py

View check run for this annotation

Codecov / codecov/patch

core/dbt/adapters/base/connections.py#L424

Added line #L424 was not covered by tests
"`execute` is not implemented for this adapter!"
)

def add_select_query(self, sql: str) -> Tuple[Connection, Any]:
"""
Expand All @@ -422,14 +433,14 @@

See https://github.com/dbt-labs/dbt-core/issues/8396 for more information.
"""
raise dbt.exceptions.NotImplementedError(
raise dbt.common.exceptions.base.NotImplementedError(

Check warning on line 436 in core/dbt/adapters/base/connections.py

View check run for this annotation

Codecov / codecov/patch

core/dbt/adapters/base/connections.py#L436

Added line #L436 was not covered by tests
"`add_select_query` is not implemented for this adapter!"
)

@classmethod
def data_type_code_to_name(cls, type_code: Union[int, str]) -> str:
"""Get the string representation of the data type from the type_code."""
# https://peps.python.org/pep-0249/#type-objects
raise dbt.exceptions.NotImplementedError(
raise dbt.common.exceptions.base.NotImplementedError(

Check warning on line 444 in core/dbt/adapters/base/connections.py

View check run for this annotation

Codecov / codecov/patch

core/dbt/adapters/base/connections.py#L444

Added line #L444 was not covered by tests
"`data_type_code_to_name` is not implemented for this adapter!"
)
25 changes: 14 additions & 11 deletions core/dbt/adapters/base/impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,25 @@
import agate
import pytz

from dbt.exceptions import (
from dbt.adapters.exceptions import (
SnapshotTargetIncompleteError,
SnapshotTargetNotSnapshotTableError,
NullRelationDropAttemptedError,
NullRelationCacheAttemptedError,
RelationReturnedMultipleResultsError,
UnexpectedNonTimestampError,
RenameToNoneAttemptedError,
QuoteConfigTypeError,
)

from dbt.common.exceptions import (
NotImplementedError,
DbtInternalError,
DbtRuntimeError,
DbtValidationError,
UnexpectedNullError,
MacroArgTypeError,
MacroResultError,
NotImplementedError,
NullRelationCacheAttemptedError,
NullRelationDropAttemptedError,
QuoteConfigTypeError,
RelationReturnedMultipleResultsError,
RenameToNoneAttemptedError,
SnapshotTargetIncompleteError,
SnapshotTargetNotSnapshotTableError,
UnexpectedNonTimestampError,
UnexpectedNullError,
)

from dbt.adapters.protocol import AdapterConfig
Expand Down
2 changes: 1 addition & 1 deletion core/dbt/adapters/base/query_headers.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from dbt.adapters.contracts.connection import AdapterRequiredConfig, QueryComment
from dbt.contracts.graph.nodes import ResultNode
from dbt.contracts.graph.manifest import Manifest
from dbt.exceptions import DbtRuntimeError
from dbt.common.exceptions import DbtRuntimeError


class NodeWrapper:
Expand Down
13 changes: 5 additions & 8 deletions core/dbt/adapters/base/relation.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,13 @@
Policy,
Path,
)
from dbt.exceptions import (
ApproximateMatchError,
DbtInternalError,
MultipleDatabasesNotAllowedError,
)
from dbt.common.exceptions import DbtInternalError
from dbt.adapters.exceptions import MultipleDatabasesNotAllowedError, ApproximateMatchError
from dbt.node_types import NodeType
from dbt.common.utils import filter_null_values, deep_merge
from dbt.adapters.utils import classproperty

import dbt.exceptions
import dbt.common.exceptions


Self = TypeVar("Self", bound="BaseRelation")
Expand Down Expand Up @@ -101,7 +98,7 @@

if not search:
# nothing was passed in
raise dbt.exceptions.DbtRuntimeError(
raise dbt.common.exceptions.DbtRuntimeError(

Check warning on line 101 in core/dbt/adapters/base/relation.py

View check run for this annotation

Codecov / codecov/patch

core/dbt/adapters/base/relation.py#L101

Added line #L101 was not covered by tests
"Tried to match relation, but no search path was passed!"
)

Expand Down Expand Up @@ -387,7 +384,7 @@

def __post_init__(self):
if not isinstance(self.information_schema_view, (type(None), str)):
raise dbt.exceptions.CompilationError(
raise dbt.common.exceptions.CompilationError(

Check warning on line 387 in core/dbt/adapters/base/relation.py

View check run for this annotation

Codecov / codecov/patch

core/dbt/adapters/base/relation.py#L387

Added line #L387 was not covered by tests
"Got an invalid name: {}".format(self.information_schema_view)
)

Expand Down
6 changes: 3 additions & 3 deletions core/dbt/adapters/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
_make_ref_key_dict,
_ReferenceKey,
)
from dbt.exceptions import (
DependentLinkNotCachedError,
from dbt.common.exceptions.cache import (
NewNameAlreadyInCacheError,
NoneRelationFoundError,
ReferencedLinkNotCachedError,
DependentLinkNotCachedError,
TruncatedModelNameCausedCollisionError,
NoneRelationFoundError,
)
from dbt.common.events.functions import fire_event, fire_event_if
from dbt.common.events.types import CacheAction, CacheDumpGraph
Expand Down
4 changes: 4 additions & 0 deletions core/dbt/adapters/exceptions/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from dbt.adapters.exceptions.compilation import * # noqa
from dbt.adapters.exceptions.alias import * # noqa
from dbt.adapters.exceptions.database import * # noqa
from dbt.adapters.exceptions.connection import * # noqa
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from typing import Mapping, Any

from dbt.exceptions import DbtValidationError
from dbt.common.exceptions import DbtValidationError


class AliasError(DbtValidationError):
Expand Down
Loading