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 Replaceable class #7844

Closed
wants to merge 5 commits into from
Closed
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-20230613-093013.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
kind: Under the Hood
body: Remove uses of Replaceable class
time: 2023-06-13T09:30:13.30422-04:00
custom:
Author: gshank
Issue: "7802"
14 changes: 8 additions & 6 deletions core/dbt/adapters/base/relation.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from collections.abc import Hashable
from dataclasses import dataclass, field
from dataclasses import dataclass, field, replace
from typing import Optional, TypeVar, Any, Type, Dict, Iterator, Tuple, Set

from dbt.contracts.graph.nodes import SourceDefinition, ManifestNode, ResultNode, ParsedNode
Expand Down Expand Up @@ -109,7 +109,7 @@ def matches(
return exact_match

def replace_path(self, **kwargs):
return self.replace(path=self.path.replace(**kwargs))
return replace(self, path=replace(self.path, **kwargs))

def quote(
self: Self,
Expand All @@ -126,7 +126,7 @@ def quote(
)

new_quote_policy = self.quote_policy.replace_dict(policy)
return self.replace(quote_policy=new_quote_policy)
return replace(self, quote_policy=new_quote_policy)

def include(
self: Self,
Expand All @@ -143,7 +143,7 @@ def include(
)

new_include_policy = self.include_policy.replace_dict(policy)
return self.replace(include_policy=new_include_policy)
return replace(self, include_policy=new_include_policy)

def information_schema(self, view_name=None) -> "InformationSchema":
# some of our data comes from jinja, where things can be `Undefined`.
Expand Down Expand Up @@ -384,7 +384,8 @@ def get_include_policy(
relation,
information_schema_view: Optional[str],
) -> Policy:
return relation.include_policy.replace(
return replace(
relation.include_policy,
database=relation.database is not None,
schema=False,
identifier=True,
Expand All @@ -396,7 +397,8 @@ def get_quote_policy(
relation,
information_schema_view: Optional[str],
) -> Policy:
return relation.quote_policy.replace(
return replace(
relation.quote_policy,
identifier=False,
)

Expand Down
5 changes: 3 additions & 2 deletions core/dbt/adapters/cache.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import threading
from copy import deepcopy
from typing import Any, Dict, Iterable, List, Optional, Set, Tuple
from dataclasses import replace

from dbt.adapters.reference_keys import (
_make_ref_key,
Expand Down Expand Up @@ -296,11 +297,11 @@ def add_link(self, referenced, dependent):
return
if ref_key not in self.relations:
# Insert a dummy "external" relation.
referenced = referenced.replace(type=referenced.External)
referenced = replace(referenced, type=referenced.External)
self.add(referenced)
if dep_key not in self.relations:
# Insert a dummy "external" relation.
dependent = dependent.replace(type=referenced.External)
dependent = replace(dependent, type=referenced.External)
self.add(dependent)
fire_event(
CacheAction(
Expand Down
5 changes: 2 additions & 3 deletions core/dbt/contracts/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
ValidatedStringMixin,
register_pattern,
)
from dbt.contracts.util import Replaceable


class Identifier(ValidatedStringMixin):
Expand Down Expand Up @@ -54,7 +53,7 @@ class ConnectionState(StrEnum):


@dataclass(init=False)
class Connection(ExtensibleDbtClassMixin, Replaceable):
class Connection(ExtensibleDbtClassMixin):
type: Identifier
name: Optional[str] = None
state: ConnectionState = ConnectionState.INIT
Expand Down Expand Up @@ -123,7 +122,7 @@ def resolve(self, connection: Connection) -> Connection:
# for why we have type: ignore. Maybe someday dataclasses + abstract classes
# will work.
@dataclass # type: ignore
class Credentials(ExtensibleDbtClassMixin, Replaceable, metaclass=abc.ABCMeta):
class Credentials(ExtensibleDbtClassMixin, metaclass=abc.ABCMeta):
database: str
schema: str
_ALIASES: ClassVar[Dict[str, str]] = field(default={}, init=False)
Expand Down
6 changes: 3 additions & 3 deletions core/dbt/contracts/graph/manifest.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import enum
from dataclasses import dataclass, field
from dataclasses import dataclass, field, replace
from itertools import chain, islice
from mashumaro.mixins.msgpack import DataClassMessagePackMixin
from multiprocessing.synchronize import Lock
Expand Down Expand Up @@ -1154,7 +1154,7 @@ def merge_from_artifact(
)
):
merged.add(unique_id)
self.nodes[unique_id] = node.replace(deferred=True)
self.nodes[unique_id] = replace(node, deferred=True)

# Rebuild the flat_graph, which powers the 'graph' context variable,
# now that we've deferred some nodes
Expand All @@ -1179,7 +1179,7 @@ def add_from_artifact(
current = self.nodes.get(unique_id)
if current and (node.resource_type in refables and not node.is_ephemeral):
state_relation = RelationalNode(node.database, node.schema, node.alias)
self.nodes[unique_id] = current.replace(state_relation=state_relation)
self.nodes[unique_id] = replace(current, state_relation=state_relation)

# Methods that were formerly in ParseResult

Expand Down
8 changes: 4 additions & 4 deletions core/dbt/contracts/graph/model_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
)
from dbt.contracts.graph.unparsed import AdditionalPropertiesAllowed, Docs
from dbt.contracts.graph.utils import validate_color
from dbt.contracts.util import Replaceable, list_str
from dbt.exceptions import DbtInternalError, CompilationError
from dbt.contracts.util import list_str
from dbt import hooks
from dbt.node_types import NodeType

Expand Down Expand Up @@ -202,12 +202,12 @@ def default(cls) -> "OnConfigurationChangeOption":


@dataclass
class ContractConfig(dbtClassMixin, Replaceable):
class ContractConfig(dbtClassMixin):
enforced: bool = False


@dataclass
class Hook(dbtClassMixin, Replaceable):
class Hook(dbtClassMixin):
sql: str
transaction: bool = True
index: Optional[int] = None
Expand All @@ -217,7 +217,7 @@ class Hook(dbtClassMixin, Replaceable):


@dataclass
class BaseConfig(AdditionalPropertiesAllowed, Replaceable):
class BaseConfig(AdditionalPropertiesAllowed):

# enable syntax like: config['key']
def __getitem__(self, key):
Expand Down
26 changes: 13 additions & 13 deletions core/dbt/contracts/graph/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
UnparsedSourceTableDefinition,
UnparsedColumn,
)
from dbt.contracts.util import Replaceable, AdditionalPropertiesMixin
from dbt.contracts.util import AdditionalPropertiesMixin
from dbt.events.functions import warn_or_error
from dbt.exceptions import ParsingError, ContractBreakingChangeError
from dbt.events.types import (
Expand Down Expand Up @@ -84,7 +84,7 @@


@dataclass
class BaseNode(dbtClassMixin, Replaceable):
class BaseNode(dbtClassMixin):
"""All nodes or node-like objects in this file should have this as a base class"""

name: str
Expand Down Expand Up @@ -201,7 +201,7 @@ class ModelLevelConstraint(ColumnLevelConstraint):


@dataclass
class ColumnInfo(AdditionalPropertiesMixin, ExtensibleDbtClassMixin, Replaceable):
class ColumnInfo(AdditionalPropertiesMixin, ExtensibleDbtClassMixin):
"""Used in all ManifestNodes and SourceDefinition"""

name: str
Expand All @@ -215,14 +215,14 @@ class ColumnInfo(AdditionalPropertiesMixin, ExtensibleDbtClassMixin, Replaceable


@dataclass
class Contract(dbtClassMixin, Replaceable):
class Contract(dbtClassMixin):
enforced: bool = False
checksum: Optional[str] = None


# Metrics, exposures,
@dataclass
class HasRelationMetadata(dbtClassMixin, Replaceable):
class HasRelationMetadata(dbtClassMixin):
database: Optional[str]
schema: str

Expand All @@ -238,7 +238,7 @@ def __pre_deserialize__(cls, data):


@dataclass
class MacroDependsOn(dbtClassMixin, Replaceable):
class MacroDependsOn(dbtClassMixin):
"""Used only in the Macro class"""

macros: List[str] = field(default_factory=list)
Expand Down Expand Up @@ -284,7 +284,7 @@ def identifier(self):


@dataclass
class ParsedNodeMandatory(GraphNode, HasRelationMetadata, Replaceable):
class ParsedNodeMandatory(GraphNode, HasRelationMetadata):
alias: str
checksum: FileHash
config: NodeConfig = field(default_factory=NodeConfig)
Expand Down Expand Up @@ -485,7 +485,7 @@ def is_public_node(self):


@dataclass
class InjectedCTE(dbtClassMixin, Replaceable):
class InjectedCTE(dbtClassMixin):
"""Used in CompiledNodes as part of ephemeral model processing"""

id: str
Expand Down Expand Up @@ -555,7 +555,7 @@ def depends_on_macros(self):


@dataclass
class FileSlice(dbtClassMixin, Replaceable):
class FileSlice(dbtClassMixin):
"""Provides file slice level context about what something was created from.

Implementation of the dbt-semantic-interfaces `FileSlice` protocol
Expand All @@ -568,7 +568,7 @@ class FileSlice(dbtClassMixin, Replaceable):


@dataclass
class SourceFileMetadata(dbtClassMixin, Replaceable):
class SourceFileMetadata(dbtClassMixin):
"""Provides file context about what something was created from.

Implementation of the dbt-semantic-interfaces `Metadata` protocol
Expand Down Expand Up @@ -925,7 +925,7 @@ def test_node_type(self):


@dataclass
class TestMetadata(dbtClassMixin, Replaceable):
class TestMetadata(dbtClassMixin):
name: str
# kwargs are the args that are left in the test builder after
# removing configs. They are set from the test builder when
Expand Down Expand Up @@ -1366,7 +1366,7 @@ def denominator_measure_reference(self) -> Optional[MeasureReference]:


@dataclass
class MetricReference(dbtClassMixin, Replaceable):
class MetricReference(dbtClassMixin):
sql: Optional[Union[str, int]] = None
unique_id: Optional[str] = None

Expand Down Expand Up @@ -1507,7 +1507,7 @@ class SemanticModel(GraphNode):


@dataclass
class ParsedPatch(HasYamlMetadata, Replaceable):
class ParsedPatch(HasYamlMetadata):
name: str
description: str
meta: Dict[str, Any]
Expand Down
Loading