Skip to content

fix(mcp): include semantic views in get_dashboard_datasets - #44269

Merged
aminghadersohi merged 2 commits into
apache:masterfrom
mikebridge:sc-120961-dashboard-datasets-explorable
Sep 17, 2026
Merged

aminghadersohi merged 2 commits into
apache:masterfrom
mikebridge:sc-120961-dashboard-datasets-explorable

Conversation

@mikebridge

Copy link
Copy Markdown
Member

SUMMARY

get_dashboard_datasets groups a dashboard's charts by datasource, but resolved each group through Slice.datasource, which is deliberately SqlaTable-only (access checks and exports depend on that type). A chart targeting a semantic view therefore contributed nothing, and a dashboard whose charts all target a semantic view answered dataset_count: 0, datasets: [] — the agent has no way to learn what columns or metrics that dashboard actually uses.

Each group is now resolved by its datasource_type: semantic-view charts go through the type-guarded Slice.semantic_view relationship (so a same-id table can never be mistaken for a view — the grouping key already includes the type), tables keep Slice.datasource. Both kinds are Explorables exposing columns / metrics, so the existing serialization is shared. Access is checked per kind: has_dataset_access for tables, the view's own raise_for_access (view perm or semantic-layer perm) for views, failing closed on any unexpected error — security_manager.can_access_datasource expects a BaseDatasource and cannot be used for a view. The view relationship is eager-loaded alongside the existing table chain.

Response additions on each entry (existing fields and their values unchanged):

field table semantic view
datasource_type "table" (default) "semantic_view"
name table name view name
semantic_layer null {uuid, name} (a semantic layer is keyed by UUID; it has no integer id)
table_name / schema / database unchanged null

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

Live superset mcp run, dashboard holding one table chart and one semantic-view chart:

before:  dataset_count: 0   datasets: []
after:   dataset_count: 2   inaccessible: 0
  - semantic_view id=1 name="Jaffle Shop" table_name=None database=None
    semantic_layer={uuid: 428c92c2…, name: "dbt Semantic Layer (MetricFlow)"}
    columns=27 (9 temporal) metrics=23 chart_count=1
  - table id=2 name="dashboards" table_name="dashboards" database="sc120961_control"
    semantic_layer=None columns=19 (3 temporal) metrics=1 chart_count=1

TESTING INSTRUCTIONS

pytest tests/unit_tests/mcp_service/dashboard/

New tests cover the mixed dashboard, a table and a view sharing id 1 on one dashboard (two entries, not one), an inaccessible view (excluded and counted in inaccessible_dataset_count while the table on the same dashboard is still returned), and the view-only dashboard — that last one was verified red-first (assert 0 == 1 before the change).

ADDITIONAL INFORMATION

  • Has associated issue: sc-120961
  • Required feature flags:
  • Changes UI
  • Includes DB Migration (follow approval process in SIP-59)
    • Migration is atomic, supports rollback & is backwards-compatible
    • Confirm DB migration upgrade and downgrade tested
    • Runtime estimates and downtime expectations provided
  • Introduces new feature or API
  • Removes existing feature or API

🤖 Generated with Claude Code

https://claude.ai/code/session_01267VBWbvWTNZUg9GvXKgkC

`get_dashboard_datasets` grouped a dashboard's charts by datasource but
resolved each group through `Slice.datasource`, which is deliberately
`SqlaTable`-only, so a chart on a semantic view contributed nothing: a
dashboard whose charts all target a semantic view answered
`dataset_count 0, datasets []`.

Resolve each group by its `datasource_type`: semantic-view charts go
through the type-guarded `Slice.semantic_view` relationship (a same-id
table can never be confused with a view; the grouping key already
includes the type), tables through `Slice.datasource` as before. Both
kinds are `Explorable`s, so the column/metric serialization is shared.
Access is checked per kind — `has_dataset_access` for tables, the view's
own `raise_for_access` (view perm or layer perm) for views, failing
closed on any other error. The view relationship is eager-loaded next to
the table chain.

Each entry now carries `datasource_type` (`table` | `semantic_view`,
default `table`), `name` (the Explorable's display name) and, for views,
`semantic_layer` (`uuid`, `name` — a semantic layer is keyed by UUID and
has no integer id); `table_name`, `schema` and `database` are null for a
view. Existing fields and their defaults are unchanged.

Verified on a live `superset mcp run` with a dashboard holding one table
chart and one semantic-view chart: both entries returned (the view with
its 27 columns, 9 time columns and 23 metrics and its layer), where the
same call previously returned zero. Unit tests cover the mixed dashboard,
same-id table/view on one dashboard, an inaccessible view (counted,
excluded), and the view-only dashboard (red-first: 0 before the change).

Co-Authored-By: Claude Fable 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01267VBWbvWTNZUg9GvXKgkC
@bito-code-review

bito-code-review Bot commented Sep 14, 2026 •

Copy link
Copy Markdown
Contributor

Code Review Agent Run #ef3366

Actionable Suggestions - 0
Additional Suggestions - 4
  • superset/mcp_service/dashboard/schemas.py - 3
    • N+1 lazy-load for semantic views · Line 2356-2356
      `_serialize_dashboard_dataset` now reads `datasource.semantic_layer` (line 2356), and `_has_dashboard_dataset_access` -> `raise_for_access()` (models.py:748) reads `self.semantic_layer.perm`. The eager options in `get_dashboard_datasets.py` only load `Slice.semantic_view`, not the nested `semantic_layer`, so each semantic view triggers a lazy-load query. Add a nested `subqueryload` for `semantic_layer` to keep the N+1-free guarantee the comment on lines 113-115 promises.
    • Disallowed Any type annotation · Line 2329-2329
      `datasource: Any` on line 2329 violates `ANN401`. Replace with a `Protocol` type (e.g., `_DashboardDatasource`) that describes the accessed attributes. The same issue exists on line 2396 in `_has_dashboard_dataset_access`.
    • Blind exception catch · Line 2412-2412
      Catching bare `Exception` on line 2412 triggers `BLE001`. Catch a more specific exception type, or add a `# noqa: BLE001` comment with justification if a broad catch is intentional for logging.
  • superset/mcp_service/dashboard/tool/get_dashboard_datasets.py - 1
    • Redundant eager load · Line 121-121
      `Slice.semantic_view` is already declared with `lazy="selectin"` in `superset/models/slice.py`, so it is eager-loaded by default. This explicit `subqueryload` is redundant and overrides the configured strategy. Consider dropping it to keep the eager-load list consistent with the relationship's declared loading style.
Review Details
  • Files reviewed - 3 · Commit Range: 6394f41..6394f41
    • superset/mcp_service/dashboard/schemas.py
    • superset/mcp_service/dashboard/tool/get_dashboard_datasets.py
    • tests/unit_tests/mcp_service/dashboard/tool/test_get_dashboard_datasets.py
  • Files skipped - 0
  • Tools
    • MyPy (Static Code Analysis) - ✔︎ Successful
    • Astral Ruff (Static Code Analysis) - ✔︎ Successful
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful

Bito Usage Guide

Commands

Type the following command in the pull request comment and save the comment.

  • /review - Manually triggers an incremental AI Review.

  • /review full - Manually triggers a full AI Review.

  • /pause - Pauses automatic reviews on this pull request.

  • /resume - Resumes automatic reviews.

  • /resolve - Marks all Bito-posted review comments as resolved.

  • /abort - Cancels all in-progress reviews.

Refer to the documentation for additional commands.

Configuration

This repository uses Superset You can customize the agent settings here or contact your Bito workspace admin at [email protected].

Documentation & Help

AI Code Review powered by Bito Logo

@netlify

netlify Bot commented Sep 14, 2026

Copy link
Copy Markdown

✅ Deploy Preview for superset-docs-preview ready!

Name Link
🔨 Latest commit 6394f41
🔍 Latest deploy log https://app.netlify.com/projects/superset-docs-preview/deploys/6aa87d6275fb51000832b7f5
😎 Deploy Preview https://deploy-preview-44269--superset-docs-preview.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@codecov

codecov Bot commented Sep 14, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 93.54839% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 80.32%. Comparing base (ad90bf5) to head (67d690b).
⚠️ Report is 88 commits behind head on master.

Files with missing lines Patch % Lines
superset/mcp_service/dashboard/schemas.py 93.33% 0 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #44269      +/-   ##
==========================================
+ Coverage   80.20%   80.32%   +0.11%     
==========================================
  Files        2926     2929       +3     
  Lines      172919   174317    +1398     
  Branches    40115    40417     +302     
==========================================
+ Hits       138696   140015    +1319     
- Misses      31629    31632       +3     
- Partials     2594     2670      +76     
Flag Coverage Δ
hive 37.15% <41.93%> (-0.19%) ⬇️
mysql 56.58% <41.93%> (-0.34%) ⬇️
postgres 56.60% <41.93%> (-0.35%) ⬇️
presto 39.22% <41.93%> (+<0.01%) ⬆️
python 84.76% <93.54%> (+0.14%) ⬆️
sqlite 56.30% <41.93%> (-0.34%) ⬇️
unit 76.36% <93.54%> (+0.35%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@aminghadersohi
aminghadersohi self-requested a review September 15, 2026 07:48

@aminghadersohi aminghadersohi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified: both kinds are access-filtered, the pure-SQL response is byte-identical apart from the three additive keys, and reverting production reds 5 tests. Two notes inline.

inaccessible_count += 1
continue
datasets.append(_serialize_dashboard_dataset(datasource, len(slices)))
datasets.append(_serialize_dashboard_dataset(datasource, len(slices), kind))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SemanticView.columns/.metrics are provider-backed, so an unregistered layer type (KeyError) or a provider error fails the entire tool with InternalError, losing the dashboard's healthy SQL datasets too. list_metrics.py:224 degrades per-view for exactly this reason.

Suggested change
datasets.append(_serialize_dashboard_dataset(datasource, len(slices), kind))
try:
summary = _serialize_dashboard_dataset(datasource, len(slices), kind)
except Exception as exc: # noqa: BLE001
# External registry may be empty in OSS - degrade gracefully.
logger.warning("Could not serialize datasource: %s", exc)
inaccessible_count += 1
continue
datasets.append(summary)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch — addressed in 67d690b. Semantic-view metadata failures are isolated per group, logged with the view ID and counted once, while healthy tables/views remain available. The catch deliberately re-raises SQL serialization errors rather than broadening that contract. Four before-change controls covered columns/metrics with KeyError/RuntimeError, including duplicate charts and colliding IDs; all failed before the fix. The final focused file passes 19 tests, and required pre-commit (including MyPy) passed. New-head CI is running, not yet certified green.

slice_dataset.subqueryload(SqlaTable.columns),
slice_dataset.subqueryload(SqlaTable.metrics),
slice_dataset.joinedload(SqlaTable.database),
subqueryload(Dashboard.slices).subqueryload(Slice.semantic_view),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SemanticView.semantic_layer is lazy by default and always read (layer uuid/name, and raise_for_access's layer-perm fallback), leaving one SELECT per view. Chaining .joinedload(SemanticView.semantic_layer) also needs a SemanticView import above, so it is not one span.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch — addressed in 67d690b with the SemanticView import and nested joinedload of semantic_layer. Cold-session SQLite tests use the tool's actual query options with one and three distinct layers, then assert serialization adds no SELECTs. Both failed before the fix (5 versus 4 and 7 versus 4 SELECTs); the final focused file passes 19 tests and required pre-commit/MyPy passed. New-head CI is running.

Answer review threads 4014778838 and 4014778854: preserve healthy datasource groups when one semantic provider cannot load metadata, and eager-load each view's layer to avoid per-view SQL during access and serialization. Keep SQL failure behavior unchanged and pin both contracts with failing-before regression controls.
@bito-code-review

bito-code-review Bot commented Sep 17, 2026 •

Copy link
Copy Markdown
Contributor

Code Review Agent Run #f52206

Actionable Suggestions - 0
Additional Suggestions - 3
  • superset/mcp_service/dashboard/schemas.py - 2
    • Missing tests for new path · Line 2474-2486
      The new failure path (lines 2474-2486) - semantic-view serialization failure excluded and counted, table failure re-raised - has no unit tests. BITO.md adaptive rule 11730 requires tests for error scenarios of new tool logic; this branch is exactly such a scenario and is easy to regress.
    • Unnecessary noqa directive · Line 2422-2422
      `# noqa: BLE001` on lines 2422 and 2478 is a no-op: pyproject.toml ruff `select` does not include `BLE`, so BLE001 never fires and the directive only misleads readers into thinking a linter rule is being suppressed here. Prefer removing the comments or enabling the rule project-wide.
  • superset/mcp_service/dashboard/tool/get_dashboard_datasets.py - 1
    • Unbound joinedload NameError · Line 124-126
      The new eager-load chain calls `joinedload(SemanticView.semantic_layer)`, but this module only imports `subqueryload` (line 30); `joinedload` is never bound locally or at module scope, so building `eager_options` raises `NameError` on every invocation. Sibling tools (`get_dataset_info.py:30`) import both names. Add `joinedload` to the line-30 import.
Review Details
  • Files reviewed - 3 · Commit Range: 6394f41..67d690b
    • superset/mcp_service/dashboard/schemas.py
    • superset/mcp_service/dashboard/tool/get_dashboard_datasets.py
    • tests/unit_tests/mcp_service/dashboard/tool/test_get_dashboard_datasets.py
  • Files skipped - 0
  • Tools
    • MyPy (Static Code Analysis) - ✔︎ Successful
    • Astral Ruff (Static Code Analysis) - ✔︎ Successful
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful

Bito Usage Guide

Commands

Type the following command in the pull request comment and save the comment.

  • /review - Manually triggers an incremental AI Review.

  • /review full - Manually triggers a full AI Review.

  • /pause - Pauses automatic reviews on this pull request.

  • /resume - Resumes automatic reviews.

  • /resolve - Marks all Bito-posted review comments as resolved.

  • /abort - Cancels all in-progress reviews.

Refer to the documentation for additional commands.

Configuration

This repository uses Superset You can customize the agent settings here or contact your Bito workspace admin at [email protected].

Documentation & Help

AI Code Review powered by Bito Logo

@aminghadersohi
aminghadersohi self-requested a review September 17, 2026 22:04
@aminghadersohi
aminghadersohi merged commit 795cdf2 into apache:master Sep 17, 2026
76 checks passed
villebro pushed a commit that referenced this pull request Sep 20, 2026
Co-authored-by: Mike Bridge <[email protected]>
Co-authored-by: Claude Fable 5 <[email protected]>
(cherry picked from commit 795cdf2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants