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

ExposureOwner: Rename to Owner, accept additional fields, require one of 'name' or 'email' #6912

Merged
merged 2 commits into from
Feb 13, 2023
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
7 changes: 7 additions & 0 deletions .changes/unreleased/Features-20230209-092059.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
kind: Features
body: Exposure owner requires one of name or email keys, and accepts additional arbitrary
keys
time: 2023-02-09T09:20:59.300272-05:00
custom:
Author: michelleark
Issue: "6833"
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