Repository navigation
fix(datasets): return 400, not 500, for a body-less purge POST; point the database-delete refusal at the purge flow - #44264
Conversation
…safe+@requires_json endpoints (sc-120966) requires_json raised InvalidPayloadFormatError — a status-400 SupersetErrorException the app-level handler renders correctly — but 25 endpoints stack FAB's @safe OUTSIDE the decorator, and safe converts every non-BadRequest exception into a generic 500 "Fatal error" first. Reported shape: POST /api/v1/dataset/<uuid>/purge with no body → 500, making the database-delete refusal's breadcrumb lead to an apparent crash; probe-confirmed identical on chart/dashboard/ annotation-layer POSTs — every stacked endpoint carried the latent 500, unnoticed because clients always send JSON. Fixed at the single source: requires_json now RETURNS the structured 400 response, built with the same serializer as the app handler (json_error_response), so @safe never sees an exception and the error envelope stays byte-identical for the unstacked call sites (validate_parameters' existing shape pin still passes). Pinned on the reported endpoint (body-less dataset purge → 400 with INVALID_PAYLOAD_FORMAT_ERROR) and on a sibling (chart POST) to prove the fix is stack-wide. Also: the database-delete 422 message pointed at "a purge capability" that has since shipped (and at out-of-band row surgery); it now names the real flow — GET /purge-impact for the token, POST /purge with {"confirmed_impact_token": <token>} — with restore as the alternative. Co-Authored-By: Claude Fable 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01JRLEJS4mUqKBoPjSjviKUW
Code Review Agent Run #3a7660Actionable Suggestions - 0Additional Suggestions - 1
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 |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #44264 +/- ##
==========================================
- Coverage 80.40% 80.39% -0.01%
==========================================
Files 2932 2932
Lines 174525 174526 +1
Branches 40548 40548
==========================================
- Hits 140319 140314 -5
- Misses 31537 31543 +6
Partials 2669 2669
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.
One inline, on the refusal message's restore branch: verified end-to-end that following it lands on a different 422 rather than a deletable database.
| '{"confirmed_impact_token": <token>} — or restore them ' | ||
| "(POST /api/v1/dataset/<uuid>/restore) if they should live on, " | ||
| "before deleting the database." |
There was a problem hiding this comment.
Verified at this head: after a restore, delete.py:80 takes the has_live branch and raises DatabaseDeleteDatasetsExistFailedError — "Cannot delete a database that has datasets attached". Restore swaps one 422 for another, so "before deleting the database" doesn't hold on that branch.
| '{"confirmed_impact_token": <token>} — or restore them ' | |
| "(POST /api/v1/dataset/<uuid>/restore) if they should live on, " | |
| "before deleting the database." | |
| '{"confirmed_impact_token": <token>} — before deleting the ' | |
| "database. Restoring them (POST /api/v1/dataset/<uuid>/restore) " | |
| "keeps the datasets, but the database still cannot be deleted." |
There was a problem hiding this comment.
Addressed in a0e3eac with your suggested wording and matching translation entry. The real-row validation test checks the corrected message, restores the dataset, and verifies that the live-dataset refusal still blocks deletion. The wording assertion failed before the change; all 3 delete-command tests pass afterward. Also removed the unsupported import-cycle comment and hoisted json_error_response alongside the existing error_handling import. Two body-less endpoint tests and the existing unstacked envelope test pass on isolated SQLite; pre-commit and independent final-snapshot review completed.
There was a problem hiding this comment.
Verified at 10b8555: wording applied, and the new assertion discriminates — reverting the message and separately no-op'ing SoftDeleteMixin.restore() each fail test_delete_database_blocked_by_soft_deleted_dataset. Dropping the deferred import is also right: error_handling only pulls views.base under TYPE_CHECKING. Closing from my side.
Answers discussion_r4024217575 with the suggested refusal guidance and a real-row restore/validation regression. Hoist the error serializer import: its module is already imported, so the claimed cycle did not justify a deferred import. Keep the JSON error envelope unchanged and explicitly type branch-added test locals.
✅ Deploy Preview for superset-docs-preview ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Code Review Agent Run #7ab638Actionable 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 |
richardfogaca
left a comment
There was a problem hiding this comment.
Richard's agent here:
Reviewed 10b855536a. No substantive issues found; approving.
Verified:
requires_jsonnow returnsjson_error_response([ex.error], status=ex.status), which is the same call the app-levelSupersetErrorExceptionhandler makes, so unstacked call sites keep an identical envelope while@safe-wrapped endpoints no longer see an exception to convert into a 500.- Nothing else in the tree catches or asserts on
InvalidPayloadFormatErrorbeing raised from the decorator, so returning instead of raising is safe. - The refusal wording matches the restore-branch behaviour Amin verified, and the unit test now follows a real row through
restore()and asserts the live-dataset refusal still blocks deletion.
Totally optional: the old exception path logged a warning via the app handler; the new return path is silent. For a body-less request that seems fine, just noting the loss is deliberate.
Validation: CI is green on this head, including the integration suites that run the two new body-less endpoint tests.
… the database-delete refusal at the purge flow (#44264) Co-authored-by: Claude Fable 5 <[email protected]> (cherry picked from commit ae5d8d8)
SUMMARY
POST /api/v1/dataset/<uuid>/purgewith no body returned 500{"message": "Fatal error"}(sc-120966) — and the database-delete refusal's breadcrumb pointed straight at it, so a database whose only remaining datasets are soft-deleted looked undeletable without hand-editing rows. The purge flow itself is healthy:GET .../purge-impact→POST .../purgewith{"confirmed_impact_token": <token>}works end to end.Root cause (stack-wide, not one route).
requires_jsonraisedInvalidPayloadFormatError— a status-400SupersetErrorExceptionthe app-level handler renders as the proper structured 400 — but 25 endpoints stack FAB's@safeoutside the decorator, andsafeconverts every non-BadRequestexception into a generic 500 first. Probe-confirmed identical onPOST /api/v1/chart/,/api/v1/dashboard/,/api/v1/annotation_layer/with no body. Affected stacks found by sweep:databases.put;datasets.duplicate/purge;semantic_layers.configuration_schema/post/put;queries.stop_query;charts.post/put;explore/permalink.post;explore/form_data.post/put;row_level_security.post/put;dashboards.post/put/put_filters/put_chart_customizations/put_colors;dashboards/permalink.post;annotation_layers.post/put(+ nested annotations);views/users.update_me;sqllab/permalink.post;reports.put. Unnoticed until now because real clients always send JSON.Fix at the single source:
requires_jsonnow returns the structured 400 response, built with the same serializer the app handler uses (json_error_response), so@safenever sees an exception — every stacked endpoint is fixed at once, and the error envelope stays byte-identical for the unstacked call sites (the existingvalidate_parametersshape pin passes unchanged).Second part: the database-delete 422 message said "delete them permanently once a purge capability ships, or remove the underlying rows out-of-band" — the purge API is available. It now names the real flow (
GET .../purge-impactfor the token, thenPOST .../purgewith it), while explicitly explaining that restoring a dataset preserves its database reference and does not unblock database deletion.BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
API behavior. Before: body-less purge POST →
500 {"message":"Fatal error"}. After:400witherrors[0].error_type == "INVALID_PAYLOAD_FORMAT_ERROR","Request is not JSON".TESTING INSTRUCTIONS
pytest tests/integration_tests/datasets/api_tests.py -k RequiresJson— the reported endpoint (body-less purge of an archived dataset → structured 400) plus a sibling (POST /api/v1/chart/body-less → structured 400) proving the source-level fix covers every stack.pytest tests/integration_tests/databases/api_tests.py -k invalid_payload_format— the pre-existing rich-envelope pin for an unstacked endpoint, unchanged.Fresh remediation verification: 3 database-delete unit tests, 2 body-less API tests and the existing unstacked error-envelope test passed on isolated SQLite, plus changed-file pre-commit. The refusal test follows a real row through restore and checks that deletion remains blocked. Independent final-snapshot review found no publication blockers.
ADDITIONAL INFORMATION
🤖 Generated with Claude Code
https://claude.ai/code/session_01JRLEJS4mUqKBoPjSjviKUW