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

Remove core imports from dbt.artifacts component #9694

Merged
merged 6 commits into from
Apr 15, 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/Under the Hood-20240412-132000.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
kind: Under the Hood
body: Remove non dbt.artifacts dbt.* imports from dbt/artifacts
time: 2024-04-12T13:20:00.017737-07:00
custom:
Author: michelleark
Issue: "9926"
1 change: 1 addition & 0 deletions core/dbt/artifacts/exceptions/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from dbt.artifacts.exceptions.schemas import IncompatibleSchemaError
31 changes: 31 additions & 0 deletions core/dbt/artifacts/exceptions/schemas.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
from typing import Optional

from dbt_common.exceptions import DbtRuntimeError


class IncompatibleSchemaError(DbtRuntimeError):
def __init__(self, expected: str, found: Optional[str] = None) -> None:
self.expected = expected
self.found = found
self.filename = "input file"

Check warning on line 10 in core/dbt/artifacts/exceptions/schemas.py

View check run for this annotation

Codecov / codecov/patch

core/dbt/artifacts/exceptions/schemas.py#L8-L10

Added lines #L8 - L10 were not covered by tests

super().__init__(msg=self.get_message())

Check warning on line 12 in core/dbt/artifacts/exceptions/schemas.py

View check run for this annotation

Codecov / codecov/patch

core/dbt/artifacts/exceptions/schemas.py#L12

Added line #L12 was not covered by tests

def add_filename(self, filename: str):
self.filename = filename
self.msg = self.get_message()

Check warning on line 16 in core/dbt/artifacts/exceptions/schemas.py

View check run for this annotation

Codecov / codecov/patch

core/dbt/artifacts/exceptions/schemas.py#L15-L16

Added lines #L15 - L16 were not covered by tests

def get_message(self) -> str:
found_str = "nothing"
if self.found is not None:
found_str = f'"{self.found}"'

Check warning on line 21 in core/dbt/artifacts/exceptions/schemas.py

View check run for this annotation

Codecov / codecov/patch

core/dbt/artifacts/exceptions/schemas.py#L19-L21

Added lines #L19 - L21 were not covered by tests

msg = (

Check warning on line 23 in core/dbt/artifacts/exceptions/schemas.py

View check run for this annotation

Codecov / codecov/patch

core/dbt/artifacts/exceptions/schemas.py#L23

Added line #L23 was not covered by tests
f'Expected a schema version of "{self.expected}" in '
f"{self.filename}, but found {found_str}. Are you running with a "
f"different version of dbt?"
)
return msg

Check warning on line 28 in core/dbt/artifacts/exceptions/schemas.py

View check run for this annotation

Codecov / codecov/patch

core/dbt/artifacts/exceptions/schemas.py#L28

Added line #L28 was not covered by tests

CODE = 10014
MESSAGE = "Incompatible Schema"
2 changes: 1 addition & 1 deletion core/dbt/artifacts/resources/v1/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from dbt_common.contracts.config.materialization import OnConfigurationChangeOption
from dbt.artifacts.resources.base import Docs
from dbt.artifacts.resources.types import ModelHookType
from dbt.contracts.graph.utils import validate_color
from dbt.artifacts.utils.validation import validate_color
from dbt import hooks
from mashumaro.jsonschema.annotations import Pattern

Expand Down
16 changes: 6 additions & 10 deletions core/dbt/artifacts/schemas/base.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,18 @@
import dataclasses
from datetime import datetime
import functools
from mashumaro.jsonschema import build_json_schema
from mashumaro.jsonschema.dialects import DRAFT_2020_12
from typing import ClassVar, Type, TypeVar, Dict, Any, Optional

from dbt_common.clients.system import write_json, read_json
from dbt.exceptions import (
DbtInternalError,
DbtRuntimeError,
IncompatibleSchemaError,
)
from dbt.version import __version__

from dbt_common.exceptions import DbtInternalError, DbtRuntimeError
from dbt_common.events.functions import get_metadata_vars
from dbt_common.invocation import get_invocation_id
from dbt_common.dataclass_schema import dbtClassMixin

from mashumaro.jsonschema import build_json_schema
from mashumaro.jsonschema.dialects import DRAFT_2020_12
import functools
from dbt.version import __version__
from dbt.artifacts.exceptions import IncompatibleSchemaError


BASE_SCHEMAS_URL = "https://schemas.getdbt.com/"
Expand Down
11 changes: 0 additions & 11 deletions core/dbt/artifacts/schemas/results.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
from dbt.contracts.graph.nodes import ResultNode
from dbt_common.events.functions import fire_event
from dbt.events.types import TimingInfoCollected
from dbt_common.events.contextvars import get_node_info
from dbt_common.events.helpers import datetime_to_json_string
from dbt.logger import TimingProcessor
from dbt_common.utils import cast_to_str, cast_to_int
from dbt_common.dataclass_schema import dbtClassMixin, StrEnum

Expand Down Expand Up @@ -45,13 +41,6 @@ def __enter__(self):
def __exit__(self, exc_type, exc_value, traceback):
self.timing_info.end()
self.callback(self.timing_info)
# Note: when legacy logger is removed, we can remove the following line
with TimingProcessor(self.timing_info):
fire_event(
TimingInfoCollected(
timing_info=self.timing_info.to_msg_dict(), node_info=get_node_info()
)
)


class RunningStatus(StrEnum):
Expand Down
4 changes: 2 additions & 2 deletions core/dbt/artifacts/schemas/run/v5/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from datetime import datetime


from dbt.contracts.graph.nodes import CompiledNode
from dbt.artifacts.resources import CompiledResource
from dbt.artifacts.schemas.base import (
BaseArtifactMetadata,
ArtifactMixin,
Expand Down Expand Up @@ -67,7 +67,7 @@

def process_run_result(result: RunResult) -> RunResultOutput:

compiled = isinstance(result.node, CompiledNode)
compiled = isinstance(result.node, CompiledResource)

Check warning on line 70 in core/dbt/artifacts/schemas/run/v5/run.py

View check run for this annotation

Codecov / codecov/patch

core/dbt/artifacts/schemas/run/v5/run.py#L70

Added line #L70 was not covered by tests

return RunResultOutput(
unique_id=result.node.unique_id,
Expand Down
2 changes: 1 addition & 1 deletion core/dbt/contracts/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
from typing import Optional

from dbt.contracts.graph.manifest import Manifest
from dbt.artifacts.exceptions import IncompatibleSchemaError
from dbt.artifacts.schemas.manifest import WritableManifest
from dbt.artifacts.schemas.freshness import FreshnessExecutionResultArtifact
from dbt.artifacts.schemas.run import RunResultsArtifact
from dbt_common.events.functions import fire_event
from dbt.events.types import WarnStateTargetEqual
from dbt.exceptions import IncompatibleSchemaError


def load_result_state(results_path) -> Optional[RunResultsArtifact]:
Expand Down
28 changes: 0 additions & 28 deletions core/dbt/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,34 +77,6 @@ def __reduce__(self):
return (JSONValidationError, (self.typename, self.errors))


class IncompatibleSchemaError(DbtRuntimeError):
def __init__(self, expected: str, found: Optional[str] = None) -> None:
self.expected = expected
self.found = found
self.filename = "input file"

super().__init__(msg=self.get_message())

def add_filename(self, filename: str):
self.filename = filename
self.msg = self.get_message()

def get_message(self) -> str:
found_str = "nothing"
if self.found is not None:
found_str = f'"{self.found}"'

msg = (
f'Expected a schema version of "{self.expected}" in '
f"{self.filename}, but found {found_str}. Are you running with a "
f"different version of dbt?"
)
return msg

CODE = 10014
MESSAGE = "Incompatible Schema"


class AliasError(DbtValidationError):
pass

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from dbt.artifacts.schemas.base import get_artifact_schema_version
from dbt.contracts.graph.manifest import WritableManifest
from dbt.artifacts.schemas.run import RunResultsArtifact
from dbt.exceptions import IncompatibleSchemaError
from dbt.artifacts.exceptions import IncompatibleSchemaError
from dbt.tests.util import run_dbt, get_manifest

# This project must have one of each kind of node type, plus disabled versions, for
Expand Down