Skip to content

fix(charts): allow saving charts on semantic views (create/update rejected non-table datasource types) - #44416

Merged
richardfogaca merged 2 commits into
apache:masterfrom
mikebridge:sc-121388-chart-save-semantic-view
Sep 18, 2026
Merged

richardfogaca merged 2 commits into
apache:masterfrom
mikebridge:sc-121388-chart-save-semantic-view

Conversation

@mikebridge

@mikebridge mikebridge commented Sep 18, 2026 •

Copy link
Copy Markdown
Member

SUMMARY

Fixes the semantic-view chart-save regression tracked in SC-121388.

#43500 correctly rejected SQL Lab query objects, but its TABLE-only guard also rejected persistent semantic views. #43781 provides type-aware Slice.resolved_datasource resolution. This change allows only TABLE and SEMANTIC_VIEW, retaining the query/saved_query rejection.

The Cube member-identity walkthrough stopped at step 4: Save as sent datasource_type: "semantic_view" and received HTTP 422, "Datasource type is invalid". Create and overwrite can now resolve the semantic view, populate its name, and enforce datasource access.

Independent Claude review confirmed namespace-exact lookup, manager-based grants, query-context type/id binding, and denial on both POST and PUT. The review's policy-consistency and type-only coverage findings have been folded in:

  • Explore form_data keys and permalinks use the same manager policy as chart saves; semantic-view keys work instead of returning 400 for an unsupported type.
  • POST datasource-access denial returns the documented 403 instead of an unhandled 500, including TABLE denials.
  • A type-only TABLE PUT is deliberately tightened from a no-op to validation of the retained ID in the requested namespace: allowed succeeds, missing/null ID yields 422, and denied access yields 403.

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

Backend change; no UI layout change. Before: semantic-view Save as/overwrite returns 422. After: allowed saves return 201/200 and persist the semantic-view identity. Browser save/reopen on the integrated provider stack remains to be re-exercised after the core fix is consumed.

Unblocks #44370. Its browser walkthrough (save as → reopen a Cube semantic-view chart) passes only with this change applied; on master the save returns 422. The two should land in that order, or together.

TESTING INSTRUCTIONS

  1. As a user with access to a semantic view, save a new Explore chart and overwrite it. Verify the datasource remains semantic_view, including after reopening.
  2. Deny datasource access and verify 403; verify query and saved_query create requests still return 422.
  3. Exercise type-only updates for both TABLE and SEMANTIC_VIEW, including missing datasource and denied access.

Local verification on the final tree:

  • Chart command and Explore unit suites: 99 passed.
  • Semantic-save HTTP tests plus the complete chart API suite on isolated SQLite: 110 passed.
  • Changed-file pre-commit hooks: passed, including MyPy.
  • Direct Pylint on all five production Python files: 10.00/10.
  • Before production changes, regression tests reproduced the original semantic-save rejection; review-fold controls additionally failed for null IDs and the wrong Explore policy path before passing after the fold.

Follow-ups (not claimed covered): align the shared get_datasource_by_id return annotation/consumers with SemanticView; add a real Gamma view/parent-layer grant HTTP case with provider-backed metadata and permission cleanup. Existing HTTP positives use admin and denial injection tests the route's error translation. No live-provider/browser validation or PostgreSQL/MySQL run is claimed here.

ADDITIONAL INFORMATION

Codex authored; Claude independently reviewed. Human review remains required.

Keep SQL Lab query sources rejected while authorizing persistent semantic views through the manager policy. Validate retained datasource IDs on type-only updates and map POST access denial to 403. Fold independent review coverage and nullable-ID findings for SC-121388.
@bito-code-review

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

Copy link
Copy Markdown
Contributor

Code Review Agent Run #035c86

Actionable Suggestions - 0
Additional Suggestions - 1
  • superset/commands/chart/utils.py - 1
    • Legacy dataset type rejected · Line 35-35
      The allowlist accepts only `DatasourceType.TABLE` and `DatasourceType.SEMANTIC_VIEW`, but the enum also defines `DATASET = "dataset"` (`superset/utils/core.py:231`), and `superset/views/datasource/views.py:58` treats `DATASET.value` as a dataset alias. `Slice.datasource_type` is a free `String(200)` column, so a pre-existing chart row storing `'dataset'` would now fail `ChartUpdateCommand.validate` with a 422. If no such rows can exist, ignore; otherwise widen the allowlist or migrate the rows.
Review Details
  • Files reviewed - 10 · Commit Range: 1388429..1388429
    • docs/docs/using-superset/exploring-data.mdx
    • superset/charts/api.py
    • superset/commands/chart/create.py
    • superset/commands/chart/update.py
    • superset/commands/chart/utils.py
    • superset/explore/utils.py
    • tests/integration_tests/charts/semantic_save_tests.py
    • tests/unit_tests/commands/chart/create_test.py
    • tests/unit_tests/commands/chart/update_test.py
    • tests/unit_tests/explore/utils_test.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

@github-actions github-actions Bot added api Related to the REST API doc Namespace | Anything related to documentation labels Sep 18, 2026
@netlify

netlify Bot commented Sep 18, 2026

Copy link
Copy Markdown

✅ Deploy Preview for superset-docs-preview ready!

Name Link
🔨 Latest commit 1388429
🔍 Latest deploy log https://app.netlify.com/projects/superset-docs-preview/deploys/6aacd5b717259a000884d6a2
😎 Deploy Preview https://deploy-preview-44416--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.

Comment thread superset/commands/chart/update.py Resolved
@bito-code-review

Copy link
Copy Markdown
Contributor

The flagged issue is correct. In the original code, if datasource_id was None during a type-only update, the logic would fall back to the existing datasource_id from the model, potentially bypassing validation if the new datasource_type was incompatible with that ID. The PR resolves this by explicitly checking effective_id and raising a DatasourceNotFoundValidationError if it is None before proceeding with the datasource lookup and access check.

I have reviewed the changes in superset/commands/chart/update.py and they correctly implement this validation. No further action is required for this specific comment.

Regarding other comments on this PR: I have checked the provided files and there are no other review comments in the pr_comments.csv file.

superset/commands/chart/update.py

# A type-only change still selects a different datasource namespace.
                effective_id: int | None = (
                    datasource_id
                    if datasource_id is not None
                    else self._model.datasource_id
                )
                if effective_id is None:
                    raise DatasourceNotFoundValidationError()

@codecov

codecov Bot commented Sep 18, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 80.57%. Comparing base (394bca5) to head (5d3bf53).
⚠️ Report is 2 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master   #44416   +/-   ##
=======================================
  Coverage   80.56%   80.57%           
=======================================
  Files        2938     2940    +2     
  Lines      175246   175315   +69     
  Branches    40680    40689    +9     
=======================================
+ Hits       141184   141257   +73     
+ Misses      31396    31395    -1     
+ Partials     2666     2663    -3     
Flag Coverage Δ
hive 37.24% <35.71%> (-0.02%) ⬇️
mysql 56.52% <71.42%> (+0.04%) ⬆️
postgres 56.53% <71.42%> (+0.04%) ⬆️
presto 39.14% <35.71%> (-0.01%) ⬇️
python 84.88% <100.00%> (+0.01%) ⬆️
sqlite 56.25% <71.42%> (+0.04%) ⬆️
unit 76.62% <92.85%> (+0.08%) ⬆️

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.

Distinguish an omitted datasource_id from explicit null so the validation guard runs instead of authorizing the stored source while persisting null. Cover table and semantic-view cases; addresses CodeAnt thread 4044282752.

@richardfogaca richardfogaca 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.

Richard's agent here:

Reviewed 5d3bf53ad2. The authorization shape is right and I found nothing that grants access it should not. Approving, with one finding I would like fixed here or in an immediate follow-up because it affects the denial path this PR opens up.

Important: a real semantic-view denial does a provider round-trip while building the 403. create.py, update.py, and explore/utils.py all end in security_manager.raise_for_access(datasource=<SemanticView>). On denial, get_datasource_access_error_object and get_datasource_access_link in security/manager.py both read datasource.data["id"], and SemanticView.data calls implementation.get_metrics() / _unique_dimensions, which instantiates the provider from the layer configuration. So a Gamma user without access to view 42 posting datasource_type=semantic_view, datasource_id=42 makes Superset call Cube/Snowflake before it can say 403. If the provider is unreachable, credentials rotated, or the layer type is not registered, the raised exception is not a security exception, so validate() lets it escape and @transaction turns it into a 422 "Fatal error" (500 on the form_data path, where only SupersetSecurityException is swallowed). This is pre-existing in the manager, not introduced here, and it is fail-closed, but the PR body's "denial returns the documented 403" only holds when the provider answers, and the unit fixture had to patch SemanticView.data for exactly this reason. Small suggestion: use datasource.id in those two manager call sites (the value is the same for tables), and add a Gamma denial test with the provider mocked to raise, so the 403 is pinned without a provider.

Observations, non-blocking:

  • The SEMANTIC_LAYERS flag is not consulted on save: validate_chart_datasource_type accepts semantic_view regardless, while the datasource API 404s when the flag is off. Only reachable for rows created while the flag was on. Could we gate the same way, or note the asymmetry?
  • The body says PUT binds query-context type/id; at head only the query-context-only update path checks that, so a full PUT with a query_context pointing at a different {id, type} is not validated. Pre-existing and unchanged, just worth not over-claiming.
  • The negative tests inject denial via a mocked raise_for_access; no test drives real Gamma perm evaluation. The body already lists that as a follow-up.

Verified with no issues: lookups are namespace-exact in both directions (a view id with type=table resolves a table or 422s, never a view); the type-only update path re-resolves the retained id in the requested namespace and re-checks access; datasource_id: null 422s before lookup; the form_data branch cannot reach the dashboard/guest legs because saves pass only datasource=; set_related_perm lands Slice.perm = view.perm so the type-aware chart-list filter from #43848 admits layer grants; the new *_tests.py module is collected by the integration jobs; the docs paragraph matches the code. CI is green on this head.

@bito-code-review bito-code-review Bot 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.

Code Review Agent Run #d12fb6

Actionable Suggestions - 1
  • superset/commands/chart/update.py - 1
Review Details
  • Files reviewed - 2 · Commit Range: 1388429..5d3bf53
    • superset/commands/chart/update.py
    • tests/unit_tests/commands/chart/update_test.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

# A type-only change still selects a different datasource namespace.
effective_id: int | None = (
datasource_id
if "datasource_id" in self._properties

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.

Incomplete null datasource guard

The null-datasource_id rejection only fires inside if datasource_type: (line 209). When a client sends datasource_id: null without datasource_type, that block is skipped, no error is raised, and run() persists the null via ChartDAO.update (base.py:548), wiping the chart's datasource binding. The hardening added here is incomplete for the no-type case.

Code Review Run #d12fb6


Should Bito avoid suggestions like this for future reviews? (Manage Rules)

  • Yes, avoid them

@richardfogaca
richardfogaca merged commit 9d4db45 into apache:master Sep 18, 2026
78 checks passed
@mikebridge

Copy link
Copy Markdown
Member Author

@richardfogaca @aminghadersohi — immediate follow-up opened: #44432, addressing Richard's September 18, 18:21 UTC review.

0eb74a1490 reads the persisted datasource id in both denial builders. Real Gamma chart create/update and Explore form_data regressions now return 403 without touching the failing provider. Validation: 113 HTTP tests, 262 unit tests, required hooks, and independent review with zero findings.

The follow-up body explicitly defers the flag-off save asymmetry and states that query-context type/id binding is checked on create and query-context-only update, not full PUT. Please review #44432; GitHub denied this account's formal reviewer-request permission.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api Related to the REST API doc Namespace | Anything related to documentation size/L

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants