Skip to content

Commit 6a29424

Browse files
authored
Addressed Bug with Dashboard migration (#3663)
1 parent c8859d8 commit 6a29424

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

src/databricks/labs/ucx/assessment/dashboards.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,6 @@ def __init__(
173173
def _crawl(self) -> Iterable[Dashboard]:
174174
dashboards = []
175175
for sdk_dashboard in self._list_dashboards():
176-
if sdk_dashboard.id is None:
177-
continue
178176
dashboard = Dashboard.from_sdk_redash_dashboard(sdk_dashboard)
179177
dashboards.append(dashboard)
180178
return dashboards
@@ -192,7 +190,13 @@ def _list_dashboards(self) -> list[SdkRedashDashboard]:
192190
# to a small number of items in debug mode for the assessment workflow just to complete.
193191
while self._debug_listing_upper_limit is None or self._debug_listing_upper_limit > len(dashboards):
194192
try:
195-
dashboards.append(next(dashboards_iterator))
193+
dashboard = next(dashboards_iterator)
194+
if dashboard.id is None:
195+
continue
196+
# Dashboard details are not available in the listing, so we need to fetch them
197+
dashboard_details = self._get_dashboard(dashboard.id)
198+
if dashboard_details:
199+
dashboards.append(dashboard_details)
196200
except StopIteration:
197201
break
198202
except DatabricksError as e:

tests/unit/assessment/test_dashboards.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ def test_redash_dashboard_crawler_snapshot_persists_dashboards(mock_backend) ->
120120
),
121121
]
122122
ws.dashboards.list.side_effect = lambda: (dashboard for dashboard in dashboards) # Expects an iterator
123+
ws.dashboards.get.side_effect = lambda dashboard_id: dashboards[0]
123124
crawler = RedashDashboardCrawler(ws, mock_backend, "test")
124125

125126
crawler.snapshot()
@@ -155,6 +156,7 @@ def list_dashboards() -> Iterator[SdkRedashDashboard]:
155156
raise TooManyRequests("Exceeded API limit")
156157

157158
ws.dashboards.list.side_effect = list_dashboards
159+
ws.dashboards.get.side_effect = lambda dashboard_id: SdkRedashDashboard(id=dashboard_id)
158160
crawler = RedashDashboardCrawler(ws, mock_backend, "test")
159161

160162
with caplog.at_level(logging.WARNING, logger="databricks.labs.ucx.assessment.dashboards"):
@@ -170,6 +172,7 @@ def test_redash_dashboard_crawler_stops_when_debug_listing_upper_limit_reached(m
170172
ws = create_autospec(WorkspaceClient)
171173
dashboards = [SdkRedashDashboard(id="did1"), SdkRedashDashboard(id="did2")]
172174
ws.dashboards.list.side_effect = lambda: (dashboard for dashboard in dashboards)
175+
ws.dashboards.get.side_effect = lambda dashboard_id: SdkRedashDashboard(id=dashboard_id)
173176
crawler = RedashDashboardCrawler(ws, mock_backend, "test", debug_listing_upper_limit=1)
174177

175178
crawler.snapshot()
@@ -274,6 +277,7 @@ def test_redash_dashboard_crawler_snapshot_skips_dashboard_without_id(mock_backe
274277
ws = create_autospec(WorkspaceClient)
275278
dashboards = [SdkRedashDashboard(id="did1"), SdkRedashDashboard()] # Second misses dashboard id
276279
ws.dashboards.list.side_effect = lambda: (dashboard for dashboard in dashboards) # Expects an iterator
280+
ws.dashboards.get.side_effect = lambda dashboard_id: SdkRedashDashboard(id=dashboard_id)
277281
crawler = RedashDashboardCrawler(ws, mock_backend, "test")
278282

279283
crawler.snapshot()

0 commit comments

Comments
 (0)