Repository navigation
fix(mcp): include semantic views in get_dashboard_datasets - #44269
aminghadersohi merged 2 commits into
Conversation
`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
Code Review Agent Run #ef3366Actionable Suggestions - 0Additional Suggestions - 4
Review Details
Bito Usage GuideCommands Type the following command in the pull request comment and save the comment.
Refer to the documentation for additional commands. Configuration This repository uses Documentation & Help |
✅ Deploy Preview for superset-docs-preview ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Codecov Report❌ Patch coverage is
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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
aminghadersohi
left a comment
There was a problem hiding this comment.
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)) |
There was a problem hiding this comment.
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.
| 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) |
There was a problem hiding this comment.
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), |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
Code Review Agent Run #f52206Actionable Suggestions - 0Additional Suggestions - 3
Review Details
Bito Usage GuideCommands Type the following command in the pull request comment and save the comment.
Refer to the documentation for additional commands. Configuration This repository uses Documentation & Help |
Co-authored-by: Mike Bridge <[email protected]> Co-authored-by: Claude Fable 5 <[email protected]> (cherry picked from commit 795cdf2)
SUMMARY
get_dashboard_datasetsgroups a dashboard's charts by datasource, but resolved each group throughSlice.datasource, which is deliberatelySqlaTable-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 answereddataset_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-guardedSlice.semantic_viewrelationship (so a same-id table can never be mistaken for a view — the grouping key already includes the type), tables keepSlice.datasource. Both kinds areExplorables exposingcolumns/metrics, so the existing serialization is shared. Access is checked per kind:has_dataset_accessfor tables, the view's ownraise_for_access(view perm or semantic-layer perm) for views, failing closed on any unexpected error —security_manager.can_access_datasourceexpects aBaseDatasourceand 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):
datasource_type"table"(default)"semantic_view"namesemantic_layernull{uuid, name}(a semantic layer is keyed by UUID; it has no integer id)table_name/schema/databasenullBEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
Live
superset mcp run, dashboard holding one table chart and one semantic-view chart:TESTING INSTRUCTIONS
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_countwhile the table on the same dashboard is still returned), and the view-only dashboard — that last one was verified red-first (assert 0 == 1before the change).ADDITIONAL INFORMATION
🤖 Generated with Claude Code
https://claude.ai/code/session_01267VBWbvWTNZUg9GvXKgkC