acryl-datahub 1.2.0.7rc3__py3-none-any.whl → 1.2.0.7rc4__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of acryl-datahub might be problematic. Click here for more details.

datahub/sdk/dashboard.py CHANGED
@@ -3,6 +3,7 @@ from __future__ import annotations
3
3
  from datetime import datetime
4
4
  from typing import Dict, List, Optional, Type, Union
5
5
 
6
+ from deprecated.sphinx import deprecated
6
7
  from typing_extensions import Self
7
8
 
8
9
  import datahub.metadata.schema_classes as models
@@ -24,12 +25,14 @@ from datahub.sdk._shared import (
24
25
  HasTerms,
25
26
  LinksInputType,
26
27
  OwnersInputType,
28
+ ParentContainerInputType,
27
29
  TagsInputType,
28
30
  TermsInputType,
29
31
  )
30
32
  from datahub.sdk.chart import Chart
31
33
  from datahub.sdk.dataset import Dataset
32
34
  from datahub.sdk.entity import Entity, ExtraAspectsType
35
+ from datahub.utilities.sentinels import Unset, unset
33
36
 
34
37
 
35
38
  class Dashboard(
@@ -64,7 +67,7 @@ class Dashboard(
64
67
  display_name: Optional[str] = None,
65
68
  platform_instance: Optional[DataPlatformInstanceUrnOrStr] = None,
66
69
  # Dashboard properties.
67
- description: str = "",
70
+ description: Optional[str] = None,
68
71
  external_url: Optional[str] = None,
69
72
  dashboard_url: Optional[str] = None,
70
73
  custom_properties: Optional[Dict[str, str]] = None,
@@ -74,6 +77,7 @@ class Dashboard(
74
77
  charts: Optional[List[Union[ChartUrnOrStr, Chart]]] = None,
75
78
  dashboards: Optional[List[Union[DashboardUrnOrStr, Dashboard]]] = None,
76
79
  # Standard aspects.
80
+ parent_container: ParentContainerInputType | Unset = unset,
77
81
  subtype: Optional[str] = None,
78
82
  owners: Optional[OwnersInputType] = None,
79
83
  links: Optional[LinksInputType] = None,
@@ -94,18 +98,7 @@ class Dashboard(
94
98
  self._set_platform_instance(platform, platform_instance)
95
99
 
96
100
  # Initialize DashboardInfoClass with default values
97
- dashboard_info = models.DashboardInfoClass(
98
- title=display_name or name,
99
- description=description or "",
100
- lastModified=models.ChangeAuditStampsClass(
101
- lastModified=None,
102
- ),
103
- customProperties={},
104
- chartEdges=[],
105
- datasetEdges=[],
106
- dashboards=[],
107
- )
108
-
101
+ dashboard_info = self._ensure_dashboard_props(display_name=display_name)
109
102
  if last_modified:
110
103
  dashboard_info.lastModified = models.ChangeAuditStampsClass(
111
104
  lastModified=models.AuditStampClass(
@@ -114,7 +107,6 @@ class Dashboard(
114
107
  ),
115
108
  )
116
109
 
117
- # Set additional properties
118
110
  if description is not None:
119
111
  self.set_description(description)
120
112
  if display_name is not None:
@@ -129,6 +121,15 @@ class Dashboard(
129
121
  self.set_last_modified(last_modified)
130
122
  if last_refreshed is not None:
131
123
  self.set_last_refreshed(last_refreshed)
124
+ if input_datasets is not None:
125
+ self.set_input_datasets(input_datasets)
126
+ if charts is not None:
127
+ self.set_charts(charts)
128
+ if dashboards is not None:
129
+ self.set_dashboards(dashboards)
130
+
131
+ if parent_container is not unset:
132
+ self._set_container(parent_container)
132
133
  if subtype is not None:
133
134
  self.set_subtype(subtype)
134
135
  if owners is not None:
@@ -141,12 +142,6 @@ class Dashboard(
141
142
  self.set_terms(terms)
142
143
  if domain is not None:
143
144
  self.set_domain(domain)
144
- if input_datasets is not None:
145
- self.set_input_datasets(input_datasets)
146
- if charts is not None:
147
- self.set_charts(charts)
148
- if dashboards is not None:
149
- self.set_dashboards(dashboards)
150
145
 
151
146
  @classmethod
152
147
  def _new_from_graph(cls, urn: Urn, current_aspects: models.AspectBag) -> Self:
@@ -162,11 +157,13 @@ class Dashboard(
162
157
  assert isinstance(self._urn, DashboardUrn)
163
158
  return self._urn
164
159
 
165
- def _ensure_dashboard_props(self) -> models.DashboardInfoClass:
160
+ def _ensure_dashboard_props(
161
+ self, display_name: Optional[str] = None
162
+ ) -> models.DashboardInfoClass:
166
163
  """Get the dashboard properties safely."""
167
164
  return self._setdefault_aspect(
168
165
  models.DashboardInfoClass(
169
- title=self.urn.dashboard_id,
166
+ title=display_name or self.urn.dashboard_id,
170
167
  description="",
171
168
  lastModified=models.ChangeAuditStampsClass(
172
169
  lastModified=models.AuditStampClass(
@@ -186,60 +183,52 @@ class Dashboard(
186
183
  return self.urn.dashboard_id
187
184
 
188
185
  @property
186
+ @deprecated("Use display_name instead", version="1.2.0.7")
189
187
  def title(self) -> str:
190
- """Get the title of the dashboard."""
191
- return self._ensure_dashboard_props().title
188
+ """Get the display name of the dashboard."""
189
+ return self.display_name
192
190
 
191
+ @deprecated("Use set_display_name instead", version="1.2.0.7")
193
192
  def set_title(self, title: str) -> None:
194
- """Set the title of the dashboard."""
195
- props = self._ensure_dashboard_props()
196
- props.title = title
197
- self._set_aspect(props)
193
+ """Set the display name of the dashboard."""
194
+ self.set_display_name(title)
198
195
 
199
196
  @property
200
197
  def description(self) -> Optional[str]:
201
198
  """Get the description of the dashboard."""
202
- props = self._ensure_dashboard_props()
203
- return props.description
199
+ # Because description is a required field, we treat "" as None.
200
+ return self._ensure_dashboard_props().description or None
204
201
 
205
202
  def set_description(self, description: str) -> None:
206
203
  """Set the description of the dashboard."""
207
- props = self._ensure_dashboard_props()
208
- props.description = description
209
- self._set_aspect(props)
204
+ self._ensure_dashboard_props().description = description
210
205
 
211
206
  @property
212
- def display_name(self) -> Optional[str]:
207
+ def display_name(self) -> str:
213
208
  """Get the display name of the dashboard."""
214
- return self.title
209
+ return self._ensure_dashboard_props().title
215
210
 
216
211
  def set_display_name(self, display_name: str) -> None:
217
212
  """Set the display name of the dashboard."""
218
- self.set_title(display_name)
213
+ self._ensure_dashboard_props().title = display_name
219
214
 
220
215
  @property
221
216
  def external_url(self) -> Optional[str]:
222
217
  """Get the external URL of the dashboard."""
223
- props = self._ensure_dashboard_props()
224
- return props.externalUrl
218
+ return self._ensure_dashboard_props().externalUrl
225
219
 
226
220
  def set_external_url(self, external_url: str) -> None:
227
221
  """Set the external URL of the dashboard."""
228
- props = self._ensure_dashboard_props()
229
- props.externalUrl = external_url
230
- self._set_aspect(props)
222
+ self._ensure_dashboard_props().externalUrl = external_url
231
223
 
232
224
  @property
233
225
  def dashboard_url(self) -> Optional[str]:
234
226
  """Get the dashboard URL."""
235
- props = self._ensure_dashboard_props()
236
- return props.dashboardUrl
227
+ return self._ensure_dashboard_props().dashboardUrl
237
228
 
238
229
  def set_dashboard_url(self, dashboard_url: str) -> None:
239
230
  """Set the dashboard URL."""
240
- props = self._ensure_dashboard_props()
241
- props.dashboardUrl = dashboard_url
242
- self._set_aspect(props)
231
+ self._ensure_dashboard_props().dashboardUrl = dashboard_url
243
232
 
244
233
  @property
245
234
  def custom_properties(self) -> Dict[str, str]:
@@ -249,9 +238,7 @@ class Dashboard(
249
238
 
250
239
  def set_custom_properties(self, custom_properties: Dict[str, str]) -> None:
251
240
  """Set the custom properties of the dashboard."""
252
- props = self._ensure_dashboard_props()
253
- props.customProperties = custom_properties
254
- self._set_aspect(props)
241
+ self._ensure_dashboard_props().customProperties = custom_properties
255
242
 
256
243
  @property
257
244
  def last_modified(self) -> Optional[datetime]:
@@ -263,14 +250,12 @@ class Dashboard(
263
250
 
264
251
  def set_last_modified(self, last_modified: datetime) -> None:
265
252
  """Set the last modification timestamp of the dashboard."""
266
- props = self._ensure_dashboard_props()
267
- props.lastModified = models.ChangeAuditStampsClass(
253
+ self._ensure_dashboard_props().lastModified = models.ChangeAuditStampsClass(
268
254
  lastModified=models.AuditStampClass(
269
255
  time=int(last_modified.timestamp()),
270
256
  actor="urn:li:corpuser:datahub",
271
257
  ),
272
258
  )
273
- self._set_aspect(props)
274
259
 
275
260
  @property
276
261
  def last_refreshed(self) -> Optional[datetime]:
@@ -284,9 +269,7 @@ class Dashboard(
284
269
 
285
270
  def set_last_refreshed(self, last_refreshed: datetime) -> None:
286
271
  """Set the last refresh timestamp of the dashboard."""
287
- props = self._ensure_dashboard_props()
288
- props.lastRefreshed = int(last_refreshed.timestamp())
289
- self._set_aspect(props)
272
+ self._ensure_dashboard_props().lastRefreshed = int(last_refreshed.timestamp())
290
273
 
291
274
  @property
292
275
  def input_datasets(self) -> List[DatasetUrn]:
@@ -310,7 +293,6 @@ class Dashboard(
310
293
  dataset_urn = DatasetUrn.from_string(dataset)
311
294
  dataset_edges.append(models.EdgeClass(destinationUrn=str(dataset_urn)))
312
295
  props.datasetEdges = dataset_edges
313
- self._set_aspect(props)
314
296
 
315
297
  def add_input_dataset(self, input_dataset: Union[DatasetUrnOrStr, Dataset]) -> None:
316
298
  """Add an input dataset to the dashboard."""
@@ -326,7 +308,6 @@ class Dashboard(
326
308
  models.EdgeClass(destinationUrn=str(input_dataset_urn))
327
309
  )
328
310
  props.datasetEdges = dataset_edges
329
- self._set_aspect(props)
330
311
 
331
312
  def remove_input_dataset(
332
313
  self, input_dataset: Union[DatasetUrnOrStr, Dataset]
@@ -342,7 +323,6 @@ class Dashboard(
342
323
  for edge in (props.datasetEdges or [])
343
324
  if edge.destinationUrn != str(input_dataset_urn)
344
325
  ]
345
- self._set_aspect(props)
346
326
 
347
327
  @property
348
328
  def charts(self) -> List[ChartUrn]:
@@ -363,7 +343,6 @@ class Dashboard(
363
343
  chart_urn = ChartUrn.from_string(chart)
364
344
  chart_edges.append(models.EdgeClass(destinationUrn=str(chart_urn)))
365
345
  props.chartEdges = chart_edges
366
- self._set_aspect(props)
367
346
 
368
347
  def add_chart(self, chart: Union[ChartUrnOrStr, Chart]) -> None:
369
348
  """Add a chart to the dashboard."""
@@ -381,7 +360,6 @@ class Dashboard(
381
360
  if str(chart_urn) not in existing_urns:
382
361
  chart_edges.append(models.EdgeClass(destinationUrn=str(chart_urn)))
383
362
  props.chartEdges = chart_edges
384
- self._set_aspect(props)
385
363
 
386
364
  def remove_chart(self, chart: Union[ChartUrnOrStr, Chart]) -> None:
387
365
  """Remove a chart from the dashboard."""
@@ -395,7 +373,6 @@ class Dashboard(
395
373
  for edge in (props.chartEdges or [])
396
374
  if edge.destinationUrn != str(chart_urn)
397
375
  ]
398
- self._set_aspect(props)
399
376
 
400
377
  @property
401
378
  def dashboards(self) -> List[DashboardUrn]:
@@ -417,7 +394,6 @@ class Dashboard(
417
394
  else:
418
395
  dashboard_urn = DashboardUrn.from_string(dashboard)
419
396
  props.dashboards.append(models.EdgeClass(destinationUrn=str(dashboard_urn)))
420
- self._set_aspect(props)
421
397
 
422
398
  def add_dashboard(self, dashboard: Union[DashboardUrnOrStr, Dashboard]) -> None:
423
399
  """Add a dashboard to the dashboard."""