Fix silent deletes: 204 handling, batch-delete guard, mutation feedback#7
Merged
Conversation
Deleting a batch did nothing visible — no refresh, no message. Root causes: - api.js called res.json() on every OK response, including 204 No Content (DELETE), throwing "Unexpected end of JSON input". The thrown error skipped the list reload, so the item stayed on screen. Return null on 204. - delete_batch did a raw db.delete + commit; Batch has no cascade and the FKs have no ondelete, so deleting a batch with students/sessions/payments raised a Postgres FK error -> HTTP 500. Now block with a clean 409 naming the blockers (active enrollments / sessions / payments), and sweep the dead soft-deleted join rows left by unenroll before deleting. - No mutation button gave feedback. Wrap delete/remove/unenroll/deactivate/ disable handlers in try/catch with success/error toasts (the toast system already existed and was used elsewhere). Verified end-to-end via Docker + Playwright: block path -> 409 + error toast + card stays; success path -> 204 + success toast + card removed; create flows unregressed (8/8). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Deleting an item (e.g. a batch) gave no visible result — the page didn't refresh and there was no success/error indication.
Root causes
api.jsparsed empty204bodies as JSON.DELETEreturns204 No Content, butrequest()always calledres.json(), throwing "Unexpected end of JSON input". That thrown error skipped the listreload(), so the deleted item stayed on screen. → Returnnullon204.delete_batch500'd on dependents. Rawdb.delete + commit;Batchhas no cascade and the FKs (BatchEnrollment/Session/Payment→batch_id) have noondelete, so deleting a batch with students/sessions/payments raised a Postgres FK error. → Block with a clean 409 naming the blockers (active enrollments / sessions / payments), and sweep the dead soft-deleted join rows left byunenrollbefore deleting. No destructive cascade.Files
frontend/src/api.js—204→nullbackend/app/routers/batches.py— 409 guard + dead-row cleanupfrontend/src/pages/{Batches,Tutors,Users,StudentDetail}.jsx— toast feedbackVerification (Docker + Playwright)
🤖 Generated with Claude Code