Skip to content

fix(datasets): return 400, not 500, for a body-less purge POST; point the database-delete refusal at the purge flow - #44264

Merged
aminghadersohi merged 3 commits into
apache:masterfrom
mikebridge:sc-120966-purge-no-body-400
Sep 18, 2026
Merged

aminghadersohi merged 3 commits into
apache:masterfrom
mikebridge:sc-120966-purge-no-body-400

Conversation

@mikebridge

@mikebridge mikebridge commented Sep 14, 2026 •

Copy link
Copy Markdown
Member

SUMMARY

POST /api/v1/dataset/<uuid>/purge with 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 .../purge with {"confirmed_impact_token": <token>} works end to end.

Root cause (stack-wide, not one route). requires_json raised InvalidPayloadFormatError — a status-400 SupersetErrorException the app-level handler renders as the proper structured 400 — but 25 endpoints stack FAB's @safe outside the decorator, and safe converts every non-BadRequest exception into a generic 500 first. Probe-confirmed identical on POST /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_json now returns the structured 400 response, built with the same serializer the app handler uses (json_error_response), so @safe never sees an exception — every stacked endpoint is fixed at once, and the error envelope stays byte-identical for the unstacked call sites (the existing validate_parameters shape 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-impact for the token, then POST .../purge with 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: 400 with errors[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

  • Has associated issue: sc-120966
  • Required feature flags:
  • Changes UI
  • Includes DB Migration (follow approval process in SIP-59)
    • Migration is atomic, supports rollback & is backwards-compatible
    • Confirm DB migration upgrade and downgrade tested
    • Runtime estimates and downtime expectations provided
  • Introduces new feature or API
  • Removes existing feature or API

🤖 Generated with Claude Code

https://claude.ai/code/session_01JRLEJS4mUqKBoPjSjviKUW

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

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

Copy link
Copy Markdown
Contributor

Code Review Agent Run #3a7660

Actionable Suggestions - 0
Additional Suggestions - 1
  • superset/views/base_api.py - 1
    • Misleading import-cycle comment · Line 108-110
      The comment's justification is inaccurate: `error_handling` imports `views.base` only under `typing.TYPE_CHECKING` (line 55-56), and `base_api.py` already imports `handle_api_exception` from `error_handling` at top level (line 51). There is no runtime import cycle, so the deferred import adds no benefit and the comment misleads future maintainers about the import graph.
Review Details
  • Files reviewed - 4 · Commit Range: 0afd323..0afd323
    • superset/commands/database/exceptions.py
    • superset/translations/messages.pot
    • superset/views/base_api.py
    • tests/integration_tests/datasets/api_tests.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 the i18n Namespace | Anything related to localization label Sep 14, 2026
@codecov

codecov Bot commented Sep 14, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 80.39%. Comparing base (4c77b0b) to head (10b8555).

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              
Flag Coverage Δ
hive 37.15% <33.33%> (-0.01%) ⬇️
mysql 56.60% <100.00%> (+<0.01%) ⬆️
postgres 56.62% <100.00%> (+<0.01%) ⬆️
presto 39.22% <33.33%> (-0.01%) ⬇️
python 84.75% <100.00%> (-0.01%) ⬇️
sqlite 56.32% <100.00%> (+<0.01%) ⬆️
unit 76.35% <33.33%> (-0.01%) ⬇️

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.

@aminghadersohi
aminghadersohi self-requested a review September 16, 2026 06:26

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

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.

Comment on lines +176 to +178
'{"confirmed_impact_token": <token>} — or restore them '
"(POST /api/v1/dataset/<uuid>/restore) if they should live on, "
"before deleting the database."

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.

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.

Suggested change
'{"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."

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

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.

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.
@pull-request-size pull-request-size Bot added size/L and removed size/M labels Sep 16, 2026
@netlify

netlify Bot commented Sep 16, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for superset-docs-preview ready!

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

@bito-code-review

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

Copy link
Copy Markdown
Contributor

Code Review Agent Run #7ab638

Actionable Suggestions - 0
Review Details
  • Files reviewed - 5 · Commit Range: 0afd323..10b8555
    • superset/commands/database/exceptions.py
    • superset/translations/messages.pot
    • superset/views/base_api.py
    • tests/integration_tests/datasets/api_tests.py
    • tests/unit_tests/databases/commands/delete_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

@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 10b855536a. No substantive issues found; approving.

Verified:

  • requires_json now returns json_error_response([ex.error], status=ex.status), which is the same call the app-level SupersetErrorException handler 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 InvalidPayloadFormatError being 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.

@aminghadersohi
aminghadersohi merged commit ae5d8d8 into apache:master Sep 18, 2026
76 checks passed
villebro pushed a commit that referenced this pull request Sep 20, 2026
… the database-delete refusal at the purge flow (#44264)

Co-authored-by: Claude Fable 5 <[email protected]>
(cherry picked from commit ae5d8d8)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

i18n Namespace | Anything related to localization size/L

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants