Repository navigation
fix(charts): reject non-table datasource_type instead of crashing - #43500
Conversation
Slice.datasource only ever resolves the "table" relationship, so a chart created (or repointed via update) with datasource_type "saved_query" or "query" would either crash outright or "succeed" as a chart that can never actually render: - "saved_query": SavedQuery has no .name attribute, so validate() crashes with an unhandled AttributeError -- surfaced to API clients as an opaque 500 "Fatal error" (fixes #29697). - "query": Query has a synthetic .name property (used for CTAS table naming, not a real display name), so this one doesn't crash -- it silently creates a permanently broken chart instead. CreateChartCommand and UpdateChartCommand now reject both up front with the existing DatasourceTypeInvalidError (422), matching the pattern already used for this same class of problem in explore/utils.py and dataset/duplicate.py, rather than adding a new one-off error type. Adds unit tests for both commands (TDD: written first against unfixed code to confirm they reproduce the two distinct failure modes above, then the fix, then confirmed green) and an integration test reproducing the original bug report's exact API call shape. Co-Authored-By: Claude Sonnet 5 <[email protected]>
Code Review Agent Run #816752Actionable 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 |
|
The flagged issue is correct. The current implementation in To resolve this, you should only perform the if datasource_type and datasource_type != DatasourceType.TABLE:
raise DatasourceTypeInvalidError()This ensures the check only runs when a type is supplied, preserving the existing required-field validation when it is missing. Would you like me to check the rest of the comments on this PR to see if there are other issues to address? superset/commands/chart/update.py |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #43500 +/- ##
==========================================
+ Coverage 78.93% 78.99% +0.06%
==========================================
Files 2877 2878 +1
Lines 165232 165566 +334
Branches 38184 38266 +82
==========================================
+ Hits 130429 130797 +368
+ Misses 32341 32283 -58
- Partials 2462 2486 +24
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:
|
Skip the non-table datasource_type guard entirely when datasource_type is empty, so the existing "Datasource type is required" message isn't overwritten by "Datasource type is invalid" for the same field key. Co-Authored-By: Claude Opus 4.8 <[email protected]>
Code Review Agent Run #361309Actionable 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 |
…ion fails Co-Authored-By: Claude Opus 4.8 <[email protected]>
✅ Deploy Preview for superset-docs-preview ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Code Review Agent Run #c6543bActionable 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 |
…y from table A chart update payload that sets datasource_type without also sending datasource_id skipped the non-table rejection entirely, since the guard only checked datasource_type when datasource_id was also present. That left Slice.datasource unable to resolve the chart, since its relationship only ever joins on datasource_type == 'table'. Co-Authored-By: Claude Opus 4.8 <[email protected]>
Code Review Agent Run #484877Actionable 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 |
SUMMARY
POST /api/v1/chart/(andPUT /api/v1/chart/<pk>) withdatasource_type: "saved_query"crashes with an unhandledAttributeError: 'SavedQuery' object has no attribute 'name', surfaced to API clients as an opaque 500{"message": "Fatal error"}.The deeper issue:
Slice.datasourceonly ever resolves thetablerelationship (superset/models/slice.py), so a chart pointed at any otherdatasource_typecould never actually render even if creation succeeded. That's the case fordatasource_type: "query"too —Queryhappens to have a synthetic.nameproperty (used for CTAS table naming, not a real display name), so it doesn't crash, it just silently produces a permanently broken chart instead.CreateChartCommandandUpdateChartCommandnow reject both up front with the existingDatasourceTypeInvalidError(422), matching the pattern already used for this same class of problem elsewhere in the codebase (explore/utils.py,dataset/duplicate.py), instead of adding a new one-off error type.Root-caused with help from the discussion on the issue — thanks @endimonan for the minimal repro that ruled out pivot tables as a factor and narrowed this down.
BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
Not applicable (API error-handling behavior).
TESTING INSTRUCTIONS
Written test-first: each new unit test was confirmed to fail against unfixed code (reproducing the exact
AttributeErrorforsaved_query, and the "silently succeeds with a broken chart" behavior forquery) before the fix was applied, then confirmed to pass after.Also added an integration test (
tests/integration_tests/charts/api_tests.py::test_create_chart_from_saved_query_rejected_cleanly) that reproduces the original bug report's exact API call shape end-to-end — creates a realSavedQueryrow, then assertsPOST /api/v1/chart/against it returns a clean 422 instead of a 500. Couldn't run the integration suite locally (this environment's SQLite test DB isn't migrated), so CI is the authority on that one.Manual repro before the fix, matching the original report:
ADDITIONAL INFORMATION