Skip to content

Commit

Permalink
Remove definition of Mergeable from dbt/contracts/util
Browse files Browse the repository at this point in the history
Although we've removed the definition of `Mergeable` we've ensured the
import paths are still available. We do this because this is under
`contracts`, and the sudden disappearance from the import path might
cause issues for community members using dbt-core as a library.

Ideally we'd define a `Mergeable` class here that inherits the
`dbt-common` definition and raise a deprecation warning on instantiation.
However, we don't have an established strategy to do so.
  • Loading branch information
QMalcolm committed Feb 2, 2024
1 parent a496438 commit a36cef3
Showing 1 changed file with 3 additions and 18 deletions.
21 changes: 3 additions & 18 deletions core/dbt/contracts/util.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import dataclasses
from typing import List, Any, Tuple

from dbt_common.dataclass_schema import ValidatedStringMixin, ValidationError
from dbt_common.contracts.util import Replaceable

# Leave imports of `Mergeable` and `Replaceable` to preserve import paths
from dbt_common.contracts.util import Mergeable, Replaceable # noqa:F401


SourceKey = Tuple[str, str]
Expand All @@ -24,22 +25,6 @@ class Foo:
return []


class Mergeable(Replaceable):
def merged(self, *args):
"""Perform a shallow merge, where the last non-None write wins. This is
intended to merge dataclasses that are a collection of optional values.
"""
replacements = {}
cls = type(self)
for arg in args:
for field in dataclasses.fields(cls):
value = getattr(arg, field.name)
if value is not None:
replacements[field.name] = value

return self.replace(**replacements)


class Identifier(ValidatedStringMixin):
"""Our definition of a valid Identifier is the same as what's valid for an unquoted database table name.
Expand Down

0 comments on commit a36cef3

Please sign in to comment.