Repository navigation
fix(chart): allow semantic view datasource when saving charts - #44169
Conversation
Code Review Agent Run #4e6076Actionable 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 |
✅ Deploy Preview for superset-docs-preview ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #44169 +/- ##
==========================================
- Coverage 81.02% 81.01% -0.02%
==========================================
Files 2952 2951 -1
Lines 177950 177832 -118
Branches 41248 41206 -42
==========================================
- Hits 144183 144068 -115
+ Misses 31049 31047 -2
+ Partials 2718 2717 -1
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:
|
|
The Python-Unit workflow was cancelled after all tests completed successfully (15131 passed, 5 skipped, 2 xfailed). The required check is failing only because the upstream job was cancelled. I’m unable to rerun the workflow with my contributor permissions. Could someone with maintainer access please rerun Python-Unit for this commit? |
|
@Kunal8954 codeant's thread on this is still open: |
Code Review Agent Run #509a41Actionable 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 |
| def datasource(self) -> SqlaTable | SemanticView | None: | ||
| if table := self.table: | ||
| return table | ||
| return self.semantic_view |
There was a problem hiding this comment.
SECURITY FIX REQUIRED: Returning a SemanticView here feeds its integer ID into Dashboard.datasources, while can_drill_dataset_via_dashboard_access compares only bare IDs. A guest for a dashboard containing semantic view 7 can request /datasource/samples with table ID 7 and receive raw rows from the unrelated SqlaTable 7; can this keep table-only authorization callers type-pinned or compare (datasource_type, id)?
There was a problem hiding this comment.
I’ll keep the table-only authorization path type-pinned so a semantic-view ID cannot be treated as a table ID.
There was a problem hiding this comment.
While tracing this I found two more bare id comparisons the type pinning should cover in the same sweep: _guest_token_allows_dataset(chart.datasource.id ...) in the chart branch of raise_for_access, where a guest token's dataset allowlist of table ids is compared against a semantic view id, and the native filter arm of the datasource branch, which compares target.get("datasetId") from dashboard metadata against datasource.data["id"], where SemanticView.data["id"] is the bare integer id.
| remote_side="SqlaTable.id", | ||
| lazy="subquery", | ||
| ) | ||
| semantic_view = relationship( |
There was a problem hiding this comment.
Adding this non-FK relationship makes deletion-retention policy validation fail for every Slice: dependency discovery includes relationships without a physical FK, but purge_policy_registry only declares Slice.table, so get_purge_policy(Slice) raises an incomplete-policy error before purging even a table-backed chart. Should this declare semantic_view as PRESERVE and add purge coverage?
There was a problem hiding this comment.
Thanks, I’ll update the purge policy coverage for the new relationship and verify deletion-retention validation.
There was a problem hiding this comment.
Confirmed empirically: on this branch tests/unit_tests/commands/deletion_retention/ has 14 failures, all RuntimeError: Incomplete purge policy for Slice: missing=[relationship:slices->semantic_views:->:manytoone:semantic_view], and the same suite passes on the parent commit. Since get_purge_policy(Slice) raises, chart purging itself breaks, not just the validation tests.
| if datasource_type != DatasourceType.TABLE: | ||
| if datasource_type not in { | ||
| DatasourceType.TABLE, | ||
| DatasourceType.SEMANTIC_VIEW, |
There was a problem hiding this comment.
Charts saved through this new type cannot survive their own export/import flow: the exporter removes datasource_type and only emits dataset_uuid when model.table is set, while chart import requires dataset_uuid. A semantic-view chart therefore exports YAML without any datasource pointer and immediately fails re-import; can the portable format carry a semantic-view reference before this type is accepted?
There was a problem hiding this comment.
I’ll check the chart export/import format and add semantic-view datasource references before keeping this type enabled.
There was a problem hiding this comment.
Following up on this thread: chart export/import for semantic-view charts (emitting a semantic-view datasource reference from the exported chart config and resolving it on import) is tracked as a follow-up rather than landing with this fix, so this PR is not blocked on it here. Current changes keep chart-list access, rename cascades, and trimmed-datasource validation on the new type consistent in the meantime.
| and_( | ||
| Slice.datasource_type == DatasourceType.SEMANTIC_VIEW, | ||
| ~chart_has_viewers, | ||
| Slice.perm.in_( |
There was a problem hiding this comment.
Chart visibility now depends on the stored Slice.perm, but the semantic-view and semantic-layer rename hooks update the view menu and SemanticView.perm without updating existing slices, unlike the dataset rename path. After either rename, users retain current datasource_access yet their saved charts disappear from the list; can this join the current permission or cascade the rename and cover both cases?
There was a problem hiding this comment.
I’ll trace the rename hooks and make sure existing slices keep their permissions in sync after a semantic-view rename.
| datasource = next(iter(slices)).datasource | ||
|
|
||
| if datasource: | ||
| if isinstance(datasource, BaseDatasource): |
There was a problem hiding this comment.
Grouping these slices by bare datasource_id merges the independent SqlaTable and SemanticView ID spaces. If both have ID 5, next(iter(slices)) can select the semantic-view chart and this guard drops the entire group, including the table metadata, or it can pass the semantic slice into the table's data_for_slices; can this key by (datasource_type, datasource_id) and cover a mixed dashboard collision?
There was a problem hiding this comment.
Good catch. I’ll change the grouping to include the datasource type and add coverage for table/semantic-view ID collisions.
gabotorresruiz
left a comment
There was a problem hiding this comment.
Thanks for taking this on @Kunal8954, and for keeping the command guard an explicit allowlist. I verified the core fix in a running environment on this branch: POST /api/v1/chart/ with datasource_type="semantic_view" against a real SemanticView row returns 201, set_related_perm syncs the chart's perm to the view's perm, a user without the view's datasource_access perm cannot list the chart, and a user holding it can list and open it. The same guard on the parent commit rejects the request, so the fix does what it says.
I still have to request changes, because the current head cannot pass CI:
- The new
Slice.semantic_viewrelationship breaks deletion retention. On this branchtests/unit_tests/commands/deletion_retention/has 14 failures, allRuntimeError: Incomplete purge policy for Slice: missing=[relationship:slices->semantic_views:->:manytoone:semantic_view]; the same suite passes on the parent commit. Sinceget_purge_policy(Slice)raises, chart purging itself breaks, not just the tests. This is the failure @sadpandajoe predicted on the relationship thread. Note CI has not run ona5d5b0b, so the earlier green Python-Unit run ond159207does not cover this. test_create_chart_from_semantic_viewfails as written in a real environment; details inline, including the fix I verified.- The chart filter gained a
datasource_typeguard, butDashboardAccessFilterstill has the identical unguarded join; details inline.
The direction is right and the remaining work looks mechanical. Happy to dig in with you on any of these.
|
|
||
| # Without the view's datasource_access perm, a non-owner cannot | ||
| # list/open the chart. | ||
| with self.temporary_user(gamma, login=True): |
There was a problem hiding this comment.
This test cannot pass as written. I ran it in a real environment (sqlite metadata DB plus Redis) and it fails here with 1 == 0, for two independent reasons:
self.login(ADMIN_USERNAME)above leaves an authenticated session, and FAB'sAuthDBView.loginredirects an already authenticated session without re-authenticating (theg.user.is_authenticatedearly return inflask_appbuilder/security/views.py). So everytemporary_user(..., login=True)block here still runs as admin, and admin sees the chart. Addingself.logout()before the first block fixes this; I verified it on this branch.- The
all_database_accessblock then still fails, becauseChartFilter.applyreturns the unfiltered query whensecurity_manager.can_access_all_datasources()is true, and that helper includesall_database_access. The short circuit happens before any join, so this assertion does not exercise the id ride-along protection the comment describes, and the expectation contradictsSemanticView.raise_for_access, which also grants oncan_access_all_datasources(). To pin the ride-along protection, grant access to one specific database and create a table whose id collides with the view id, then assert the chart stays hidden.
With self.logout() added and that block corrected, the rest passes for me on this branch: 201 on create, perm synced, hidden without the view perm, visible with it.
| table_alias, | ||
| and_( | ||
| Slice.datasource_id == table_alias.id, | ||
| Slice.datasource_type == DatasourceType.TABLE, |
There was a problem hiding this comment.
The guard here is right, but its sibling is still unguarded: DashboardAccessFilter._apply_viewers in superset/dashboards/filters.py has the identical join, .join(SqlaTable, Slice.datasource_id == SqlaTable.id), with no datasource_type condition. Once semantic view charts land on dashboards, a published no-viewer dashboard whose semantic view chart collides with an accessible SqlaTable.id becomes listable through that join, and conversely a dashboard containing only semantic view charts can never match the fallback even for users who hold the view perm, because the joined rows do not exist and get_dataset_access_filters(Slice) never gets to check Slice.perm. I would apply the same datasource_type == DatasourceType.TABLE guard there and add a semantic view arm mirroring this one, in this PR, since this PR is what makes such charts reachable.
| and_( | ||
| Slice.datasource_type == DatasourceType.SEMANTIC_VIEW, | ||
| ~chart_has_viewers, | ||
| Slice.perm.in_( |
There was a problem hiding this comment.
Not a blocker, a consistency question: SemanticView.raise_for_access also grants when the user holds datasource_access on the parent layer's perm, but both this branch and the chart access path (can_access_datasource, which checks only datasource.perm) look at the view perm alone. A user granted at the layer level can explore the view but cannot open or list a chart saved on it. Everything fails closed, so no security concern, but is the asymmetry intended?
…emantic-view-chart-save # Conflicts: # superset/models/slice.py # tests/unit_tests/models/slice_test.py
Code Review Agent Run #5f9766Actionable Suggestions - 0Review 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 |
gabotorresruiz
left a comment
There was a problem hiding this comment.
Thanks for the quick turnaround @Kunal8954, and good news first: two of my three blockers are gone. superset/models/slice.py dropped out of this PR in the master merge, so that relationship is upstream's now. On the merge result (refs/pull/44169/merge, eea15d7) I re-ran the suites:
tests/unit_tests/commands/deletion_retention/:98 passed.masterdeclares the missing entry itself atsuperset/commands/deletion_retention/purge_policy.py:557, so the purge policy concern is closed.DashboardAccessFilter._apply_viewersis type guarded upstream atsuperset/dashboards/filters.py:194with aSemanticViewarm, so that one is closed too.tests/unit_tests/charts/test_filters.py,tests/unit_tests/subjects/test_raise_for_access.py,tests/unit_tests/semantic_layers/models_test.pyplus deletion retention together:226 passed.
I also checked your new command tests are genuine regression tests: reverting the guard in create.py and update.py to TABLE only fails both of them.
Two blockers left.
test_update_chart_accepts_semantic_view_datasource fails on the merge result
Not your doing. The master merge added raise_if_managed_externally(self._model, ChartForbiddenError) right after the editorship check in UpdateChartCommand.validate, so the bare MagicMock at line 293 makes is_managed_externally truthy and validate() raises ChartForbiddenError before it ever reaches the datasource guard the test is about. After the merge, every other find_by_id mock in that file sets is_managed_externally=False. One line, inline below. I verified it: 1 failed, 69 passed before, 70 passed after.
test_create_chart_from_semantic_view is unchanged, and CI now confirms it
test-sqlite, test-postgres and test-mysql on 3672656 all fail at tests/integration_tests/charts/api_tests.py:778 with assert 1 == 0, which is the first temporary_user(gamma, login=True) block, the self.logout() problem. The all_database_access block right after it still needs the rewrite too: ChartFilter.apply returns the query unfiltered when can_access_all_datasources() is true (superset/charts/filters.py:120), and that helper covers all_database_access through can_access_all_databases() (superset/security/manager.py:2211 and :2221). Full detail is on the existing thread.
Two non-blockers:
- The layer grant question from last time is now the odd one out.
masterhas since aligned three siblings on it:_semantic_layer_grant_allows(superset/security/manager.py:2286, used by the datasource branch at:4838) andlayer_grant_clause(superset/dashboards/filters.py:175), whose comment explicitly anticipates the chart list mirror of that clause. Your arm atsuperset/charts/filters.py:183matchesSlice.permalone. I verified the effect on this branch: holding only the layer perm,can_access_datasource(view)isTruebut the chart is absent fromChartFilter._apply_viewers. It fails closed, so nothing unsafe, just a chart that opens but never lists. datasets_trimmed_for_slicesstill groups by baredatasource_id(superset/models/dashboard.py:353), which is @sadpandajoe's point. Theisinstancechange stops the crash but not the collision. I created aSqlaTableand aSemanticViewthat both gotid=1, put a chart from each on one dashboard, anddatasets_trimmed_for_slices()returned zero datasources in 3 of 5 runs:next(iter(slices))picked the semantic view slice, whoseSlice.datasourceisNone, and the table chart's own payload went with it. Keying by(datasource_type, datasource_id)covers both halves.
Happy to dig into either non-blocker with you.
Co-authored-by: Gabriel Torres Ruiz <[email protected]>
|
@Kunal8954 — routing a concrete dashboard regression from SC-120295 / preset-io/superset-shell#5140 to the existing SC-120289 host work. This extends the dashboard metadata concern in #44169 (comment); it is separate from MCP dashboard serialization #44269. On core Source inspection at your current Suggested regression coverage: a semantic-only dashboard must supply its authorized datasource metadata; a mixed table/semantic dashboard with colliding integer IDs must keep both identities distinct; a semantic query HTTP400 must produce a visible terminal error rather than a spinner. Preserve the existing access checks/type boundaries. Numeric's valid rendering is verified with mocked remote GraphQL/Arrow and real provider/host/frontend; its visible-error gate remains open pending the host fix. Local reproducible scripts, screenshots, response bodies and Redux evidence are saved under |
temporary_user(login=True) cannot replace an already-authenticated session, so the gamma checks ran as admin and saw the chart. Log out first, and align the all_database_access expectation with the existing can_access_all_datasources short-circuit (count 1, not 0).
Code Review Agent Run #29b394Actionable Suggestions - 0Additional Suggestions - 2
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 |
…emantic-view-chart-save
…ources by type datasets_trimmed_for_slices: group by (datasource_type, datasource_id) so a semantic-view chart and a table chart sharing an auto-increment id (e.g. both id=5) don't collapse into one group and drop the table's datasource from the validation set. semantic_layer_before_update / semantic_view_before_update: after a layer or view rename, propagate the new perm to dependent semantic-view charts so chart-list access filters (which match on Slice.perm) stay in sync. Adds regression coverage for the id collision in dashboard_test.py and for the layer-rename chart-perm cascade in semantic_layers/models_test.py.
|
Hey — could you re-run the failed |
Code Review Agent Run #f84dcfActionable Suggestions - 0Additional Suggestions - 2
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 |
…emantic-view-chart-save # Conflicts: # superset/translations/ar/LC_MESSAGES/messages.po # superset/translations/ca/LC_MESSAGES/messages.po # superset/translations/cs/LC_MESSAGES/messages.po # superset/translations/de/LC_MESSAGES/messages.po # superset/translations/en/LC_MESSAGES/messages.po # superset/translations/es/LC_MESSAGES/messages.po # superset/translations/fa/LC_MESSAGES/messages.po # superset/translations/fi/LC_MESSAGES/messages.po # superset/translations/fr/LC_MESSAGES/messages.po # superset/translations/it/LC_MESSAGES/messages.po # superset/translations/ja/LC_MESSAGES/messages.po # superset/translations/ko/LC_MESSAGES/messages.po # superset/translations/lv/LC_MESSAGES/messages.po # superset/translations/messages.pot # superset/translations/mi/LC_MESSAGES/messages.po # superset/translations/nl/LC_MESSAGES/messages.po # superset/translations/pl/LC_MESSAGES/messages.po # superset/translations/pt/LC_MESSAGES/messages.po # superset/translations/pt_BR/LC_MESSAGES/messages.po # superset/translations/ro/LC_MESSAGES/messages.po # superset/translations/ru/LC_MESSAGES/messages.po # superset/translations/sk/LC_MESSAGES/messages.po # superset/translations/sl/LC_MESSAGES/messages.po # superset/translations/sr/LC_MESSAGES/messages.po # superset/translations/sr_Latn/LC_MESSAGES/messages.po # superset/translations/ta/LC_MESSAGES/messages.po # superset/translations/th/LC_MESSAGES/messages.po # superset/translations/tr/LC_MESSAGES/messages.po # superset/translations/uk/LC_MESSAGES/messages.po # superset/translations/zh/LC_MESSAGES/messages.po # superset/translations/zh_TW/LC_MESSAGES/messages.po
gabotorresruiz
left a comment
There was a problem hiding this comment.
LGTM.
Delta since 12300a84 is three master merges plus a translations regeneration, nothing else: superset/models/dashboard.py and superset/security/manager.py are byte for byte what I approved, so the substance here is still the two rename cascades at superset/security/manager.py:4256 and :4376 plus the tests.
Verified by running rather than reading: tests/unit_tests/dashboards/datasets_test.py is 13 passed on the head (411340c8) and on the merge ref (949e630a), so the #44413 resolution held through all three merges, and test_datasets_trimmed_for_slices_keeps_colliding_ids_separate still passes in its adapted form. 1252 passed across the affected suites plus the new permission migration tests. Renaming a layer and renaming a view each still keep Slice.perm in sync.
Since #44142 landed overnight and both it and your cascades write permission rows, I checked for a collision and there is none. Its delete migration targets an explicit ten entry PVM_LIST of ("Superset", "can_*") pairs, and the rename migration's PVM_MAP is keyed on OLD_VIEW_MENU = "Superset", so neither names a datasource_access view menu, which that migration calls out as deliberate. Your cascades only touch datasource_access view menus and the two denormalized perm columns.
The messages.pot conflict is gone too: nothing under superset/translations differs from master now, and the PR is back to ten files.
|
Follow-up, please. Looking again I was behind on that last pass, sorry: gabotorresruiz had already confirmed the purge policy entry and the |
rusackas
left a comment
There was a problem hiding this comment.
LGTM, thanks for sticking with this one through all the rounds @Kunal8954. Re-checked the remaining diff myself and the two open threads sadpandajoe/gabotorresruiz raised are both closed on master now, not just addressed in this PR. Merging.
SUMMARY
Fixes #44167 — charts backed by a SIP-182 semantic view render successfully in Explore but fail to save with a 422
{"message":{"datasource_type":["Datasource type is invalid"]}}.Root cause. The datasource-type validation in
CreateChartCommand/UpdateChartCommandintroduced by #43500 (to rejectsaved_query/query, whichSlice.datasourcecan never resolve) was written as a TABLE-only check. That unintentionally also rejectssemantic_view, even though semantic views are a first-class, resolvable datasource (Slice.semantic_view,DatasourceType.SEMANTIC_VIEW).Fix. Extend the guard to an explicit allowlist of exactly the datasource types
Slicecan resolve:table— unchanged, still acceptedsemantic_view— newly acceptedsaved_query,query, and unknown types — still rejected with the existingDatasourceTypeInvalidError(422)The fix is deliberately narrow: it does not accept arbitrary non-table datasource types, does not normalize datasource types, and does not change any datasource representation.
Tests.
CreateChartCommandandUpdateChartCommandaccept asemantic_viewdatasource (validation reachesget_datasource_by_id,datasource_nameis populated);saved_query/query/bogusremain rejected in both create and update paths.POST /api/v1/chart/withdatasource_type="semantic_view"against a real semantic view row creates the chart (201), mirroring the existingsaved_queryrejection test's API shape.Honest caveat: the integration API test could not be run locally because this environment lacks a running Redis cache and the seeded integration test setup; it is left to CI. The relevant unit tests (29 passed) and all
pre-commit runchecks (mypy, ruff, ruff-format, pylint, etc.) passed locally.BEFORE/AFTER
Before:
POST /api/v1/chart/withdatasource_type: "semantic_view"→ 422Datasource type is invalid.After: the chart saves successfully (201).
TESTING INSTRUCTIONS
Integration (CI):
tests/integration_tests/charts/api_tests.py::TestChartApi::test_create_chart_from_semantic_viewADDITIONAL INFORMATION
semantic_viewtype; all previously invalid types remain invalid.