Skip to content

Commit 6e66636

Browse files
authored
Merge branch 'main' into feat/nightly
2 parents 1826851 + 69c6e97 commit 6e66636

File tree

3 files changed

+33
-30
lines changed

3 files changed

+33
-30
lines changed

src/databricks/labs/lsql/dashboards.py

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1125,20 +1125,17 @@ def create_dashboard(
11251125
"""
11261126
dashboard_metadata.validate()
11271127
serialized_dashboard = json.dumps(dashboard_metadata.as_lakeview().as_dict())
1128+
dashboard_to_create = SDKDashboard(
1129+
dashboard_id=dashboard_id,
1130+
display_name=dashboard_metadata.display_name,
1131+
parent_path=parent_path,
1132+
serialized_dashboard=serialized_dashboard,
1133+
warehouse_id=warehouse_id,
1134+
)
11281135
if dashboard_id is not None:
1129-
sdk_dashboard = self._ws.lakeview.update(
1130-
dashboard_id,
1131-
display_name=dashboard_metadata.display_name,
1132-
serialized_dashboard=serialized_dashboard,
1133-
warehouse_id=warehouse_id,
1134-
)
1136+
sdk_dashboard = self._ws.lakeview.update(dashboard_id, dashboard=dashboard_to_create.as_dict()) # type: ignore
11351137
else:
1136-
sdk_dashboard = self._ws.lakeview.create(
1137-
dashboard_metadata.display_name,
1138-
parent_path=parent_path,
1139-
serialized_dashboard=serialized_dashboard,
1140-
warehouse_id=warehouse_id,
1141-
)
1138+
sdk_dashboard = self._ws.lakeview.create(dashboard=dashboard_to_create.as_dict()) # type: ignore
11421139
if publish:
11431140
assert sdk_dashboard.dashboard_id is not None
11441141
self._ws.lakeview.publish(sdk_dashboard.dashboard_id, warehouse_id=warehouse_id)

tests/integration/test_dashboards.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import dataclasses
12
import datetime as dt
23
import json
34
import logging
@@ -52,12 +53,12 @@ def inner(**kwargs):
5253
def make_dashboard(ws, make_random):
5354
"""Clean the lakeview dashboard"""
5455

55-
def create(display_name: str = "") -> SDKDashboard:
56+
def create(*, display_name: str = "") -> SDKDashboard:
5657
if len(display_name) == 0:
5758
display_name = f"created_by_lsql_{make_random()}"
5859
else:
5960
display_name = f"{display_name} ({make_random()})"
60-
dashboard = ws.lakeview.create(display_name)
61+
dashboard = ws.lakeview.create(dashboard=SDKDashboard(display_name=display_name).as_dict())
6162
if is_in_debug():
6263
dashboard_url = f"{ws.config.host}/sql/dashboardsv3/{dashboard.dashboard_id}"
6364
webbrowser.open(dashboard_url)
@@ -110,12 +111,13 @@ def tmp_path(tmp_path, make_random):
110111
return folder
111112

112113

113-
def test_dashboards_creates_exported_dashboard_definition(ws, make_dashboard):
114+
def test_dashboards_creates_exported_dashboard_definition(ws, make_dashboard) -> None:
114115
dashboards = Dashboards(ws)
115116
sdk_dashboard = make_dashboard()
116117
dashboard_content = (Path(__file__).parent / "dashboards" / "dashboard.lvdash.json").read_text()
117118

118-
ws.lakeview.update(sdk_dashboard.dashboard_id, serialized_dashboard=dashboard_content)
119+
dashboard_to_create = dataclasses.replace(sdk_dashboard, serialized_dashboard=dashboard_content)
120+
ws.lakeview.update(sdk_dashboard.dashboard_id, dashboard=dashboard_to_create.as_dict())
119121
lakeview_dashboard = Dashboard.from_dict(json.loads(dashboard_content))
120122
new_dashboard = dashboards.get_dashboard(sdk_dashboard.path)
121123

tests/unit/test_dashboards.py

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1464,37 +1464,41 @@ def test_dashboards_saves_markdown_files_to_folder(tmp_path):
14641464
ws.assert_not_called()
14651465

14661466

1467-
def test_dashboards_calls_create_without_dashboard_id():
1467+
def test_dashboards_calls_create_without_dashboard_id() -> None:
1468+
sdk_dashboard = SDKDashboard(
1469+
dashboard_id=None,
1470+
display_name="test",
1471+
parent_path="/non/existing/path",
1472+
serialized_dashboard=json.dumps({"pages": [{"displayName": "test", "name": "test"}]}),
1473+
warehouse_id="warehouse",
1474+
)
14681475
ws = create_autospec(WorkspaceClient)
14691476
dashboards = Dashboards(ws)
14701477
dashboard_metadata = DashboardMetadata("test")
14711478

14721479
dashboards.create_dashboard(dashboard_metadata, parent_path="/non/existing/path", warehouse_id="warehouse")
14731480

1474-
ws.lakeview.create.assert_called_with(
1475-
"test",
1476-
parent_path="/non/existing/path",
1477-
serialized_dashboard=json.dumps({"pages": [{"displayName": "test", "name": "test"}]}),
1478-
warehouse_id="warehouse",
1479-
)
1481+
ws.lakeview.create.assert_called_with(dashboard=sdk_dashboard.as_dict())
14801482
ws.lakeview.update.assert_not_called()
14811483
ws.lakeview.publish.assert_not_called()
14821484

14831485

1484-
def test_dashboards_calls_update_with_dashboard_id():
1486+
def test_dashboards_calls_update_with_dashboard_id() -> None:
1487+
sdk_dashboard = SDKDashboard(
1488+
dashboard_id="id",
1489+
display_name="test",
1490+
parent_path=None,
1491+
serialized_dashboard=json.dumps({"pages": [{"displayName": "test", "name": "test"}]}),
1492+
warehouse_id="warehouse",
1493+
)
14851494
ws = create_autospec(WorkspaceClient)
14861495
dashboards = Dashboards(ws)
14871496
dashboard_metadata = DashboardMetadata("test")
14881497

14891498
dashboards.create_dashboard(dashboard_metadata, dashboard_id="id", warehouse_id="warehouse")
14901499

14911500
ws.lakeview.create.assert_not_called()
1492-
ws.lakeview.update.assert_called_with(
1493-
"id",
1494-
display_name="test",
1495-
serialized_dashboard=json.dumps({"pages": [{"displayName": "test", "name": "test"}]}),
1496-
warehouse_id="warehouse",
1497-
)
1501+
ws.lakeview.update.assert_called_with("id", dashboard=sdk_dashboard.as_dict())
14981502
ws.lakeview.publish.assert_not_called()
14991503

15001504

0 commit comments

Comments
 (0)