Skip to content

Commit

Permalink
Addressed Bug with Dashboard migration (#3663)
Browse files Browse the repository at this point in the history
  • Loading branch information
FastLee authored and JCZuurmond committed Feb 13, 2025
1 parent ed45180 commit 0cc4544
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/databricks/labs/ucx/assessment/dashboards.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,6 @@ def __init__(
def _crawl(self) -> Iterable[Dashboard]:
dashboards = []
for sdk_dashboard in self._list_dashboards():
if sdk_dashboard.id is None:
continue
dashboard = Dashboard.from_sdk_redash_dashboard(sdk_dashboard)
dashboards.append(dashboard)
return dashboards
Expand All @@ -192,7 +190,13 @@ def _list_dashboards(self) -> list[SdkRedashDashboard]:
# to a small number of items in debug mode for the assessment workflow just to complete.
while self._debug_listing_upper_limit is None or self._debug_listing_upper_limit > len(dashboards):
try:
dashboards.append(next(dashboards_iterator))
dashboard = next(dashboards_iterator)
if dashboard.id is None:
continue
# Dashboard details are not available in the listing, so we need to fetch them
dashboard_details = self._get_dashboard(dashboard.id)
if dashboard_details:
dashboards.append(dashboard_details)
except StopIteration:
break
except DatabricksError as e:
Expand Down
4 changes: 4 additions & 0 deletions tests/unit/assessment/test_dashboards.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ def test_redash_dashboard_crawler_snapshot_persists_dashboards(mock_backend) ->
),
]
ws.dashboards.list.side_effect = lambda: (dashboard for dashboard in dashboards) # Expects an iterator
ws.dashboards.get.side_effect = lambda dashboard_id: dashboards[0]
crawler = RedashDashboardCrawler(ws, mock_backend, "test")

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

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

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

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

crawler.snapshot()
Expand Down

0 comments on commit 0cc4544

Please sign in to comment.