Skip to content

Commit

Permalink
update ExposureOwner to require one of email/name, allow additional f…
Browse files Browse the repository at this point in the history
…ields
  • Loading branch information
MichelleArk committed Feb 8, 2023
1 parent abbece8 commit 3f7a1e5
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 14 deletions.
4 changes: 2 additions & 2 deletions core/dbt/contracts/graph/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
UnparsedSourceTableDefinition,
UnparsedColumn,
TestDef,
ExposureOwner,
Owner,
ExposureType,
MaturityType,
MetricFilter,
Expand Down Expand Up @@ -892,7 +892,7 @@ def search_name(self):
@dataclass
class Exposure(GraphNode):
type: ExposureType
owner: ExposureOwner
owner: Owner
resource_type: NodeType = field(metadata={"restrict": [NodeType.Exposure]})
description: str = ""
label: Optional[str] = None
Expand Down
9 changes: 6 additions & 3 deletions core/dbt/contracts/graph/unparsed.py
Original file line number Diff line number Diff line change
Expand Up @@ -424,16 +424,16 @@ class MaturityType(StrEnum):


@dataclass
class ExposureOwner(dbtClassMixin, Replaceable):
email: str
class Owner(AdditionalPropertiesAllowed, Replaceable):
email: Optional[str] = None
name: Optional[str] = None


@dataclass
class UnparsedExposure(dbtClassMixin, Replaceable):
name: str
type: ExposureType
owner: ExposureOwner
owner: Owner
description: str = ""
label: Optional[str] = None
maturity: Optional[MaturityType] = None
Expand All @@ -451,6 +451,9 @@ def validate(cls, data):
if not (re.match(r"[\w-]+$", data["name"])):
deprecations.warn("exposure-name", exposure=data["name"])

if data["owner"].get("name") is None and data["owner"].get("email") is None:
raise ValidationError("Exposure owner must have at least one of 'name' or 'email'.")


@dataclass
class MetricFilter(dbtClassMixin, Replaceable):
Expand Down
6 changes: 3 additions & 3 deletions test/unit/test_contracts_graph_parsed.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
SourceDefinition,
Documentation,
HookNode,
ExposureOwner,
Owner,
TestMetadata,
)
from dbt.contracts.graph.unparsed import (
Expand Down Expand Up @@ -2142,7 +2142,7 @@ def basic_parsed_exposure_object():
package_name='test',
path='models/something.yml',
original_file_path='models/something.yml',
owner=ExposureOwner(email='test@example.com'),
owner=Owner(email='test@example.com'),
description='',
meta={},
tags=[],
Expand Down Expand Up @@ -2195,7 +2195,7 @@ def complex_parsed_exposure_object():
name='my_exposure',
resource_type=NodeType.Exposure,
type=ExposureType.Analysis,
owner=ExposureOwner(email='test@example.com', name='A Name'),
owner=Owner(email='test@example.com', name='A Name'),
maturity=MaturityType.Low,
url='https://example.com/analyses/1',
description='my description',
Expand Down
7 changes: 5 additions & 2 deletions test/unit/test_contracts_graph_unparsed.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
UnparsedNode, UnparsedRunHook, UnparsedMacro, Time, TimePeriod,
FreshnessThreshold, Quoting, UnparsedSourceDefinition,
UnparsedSourceTableDefinition, UnparsedDocumentationFile, UnparsedColumn,
UnparsedNodeUpdate, Docs, UnparsedExposure, MaturityType, ExposureOwner,
UnparsedNodeUpdate, Docs, UnparsedExposure, MaturityType, Owner,
ExposureType, UnparsedMetric, MetricFilter, MetricTime, MetricTimePeriod
)
from dbt.contracts.results import FreshnessStatus
Expand Down Expand Up @@ -584,7 +584,9 @@ def get_ok_dict(self):
'name': 'my_exposure',
'type': 'dashboard',
'owner': {
'name': 'example',
'email': 'name@example.com',
'slack': '#channel'
},
'maturity': 'medium',
'meta': {'tool': 'my_tool'},
Expand All @@ -602,7 +604,7 @@ def test_ok(self):
exposure = self.ContractType(
name='my_exposure',
type=ExposureType.Dashboard,
owner=ExposureOwner(email='name@example.com'),
owner=Owner(name='example', email='name@example.com', _extra={'slack': '#channel'}),
maturity=MaturityType.Medium,
url='https://example.com/dashboards/1',
description='A exposure',
Expand Down Expand Up @@ -652,6 +654,7 @@ def test_bad_maturity(self):
def test_bad_owner_missing_things(self):
tst = self.get_ok_dict()
del tst['owner']['email']
del tst['owner']['name']
self.assert_fails_validation(tst)

del tst['owner']
Expand Down
4 changes: 2 additions & 2 deletions test/unit/test_graph_selector_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
ColumnInfo,
)
from dbt.contracts.graph.manifest import Manifest
from dbt.contracts.graph.unparsed import ExposureType, ExposureOwner, MetricFilter,MetricTime
from dbt.contracts.graph.unparsed import ExposureType, Owner, MetricFilter,MetricTime
from dbt.contracts.state import PreviousState
from dbt.node_types import NodeType
from dbt.graph.selector_methods import (
Expand Down Expand Up @@ -330,7 +330,7 @@ def make_exposure(pkg, name, path=None, fqn_extras=None, owner=None):
fqn_extras = []

if owner is None:
owner = ExposureOwner(email='test@example.com')
owner = Owner(email='test@example.com')

fqn = [pkg, 'exposures'] + fqn_extras + [name]
return Exposure(
Expand Down
4 changes: 2 additions & 2 deletions test/unit/test_manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

from dbt.contracts.graph.unparsed import (
ExposureType,
ExposureOwner,
Owner,
MaturityType,
MetricFilter,
MetricTime
Expand Down Expand Up @@ -83,7 +83,7 @@ def setUp(self):
'exposure.root.my_exposure': Exposure(
name='my_exposure',
type=ExposureType.Dashboard,
owner=ExposureOwner(email='some@email.com'),
owner=Owner(email='some@email.com'),
resource_type=NodeType.Exposure,
description='Test description',
maturity=MaturityType.High,
Expand Down

0 comments on commit 3f7a1e5

Please sign in to comment.