Skip to content

Fix silent deletes: 204 handling, batch-delete guard, mutation feedback#7

Merged
CaptainCo0L merged 1 commit into
mainfrom
fix-delete-feedback
Jun 29, 2026
Merged

Fix silent deletes: 204 handling, batch-delete guard, mutation feedback#7
CaptainCo0L merged 1 commit into
mainfrom
fix-delete-feedback

Conversation

@CaptainCo0L

Copy link
Copy Markdown
Owner

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

  1. api.js parsed empty 204 bodies as JSON. DELETE returns 204 No Content, but request() always called res.json(), throwing "Unexpected end of JSON input". That thrown error skipped the list reload(), so the deleted item stayed on screen. → Return null on 204.
  2. delete_batch 500'd on dependents. Raw db.delete + commit; Batch has no cascade and the FKs (BatchEnrollment/Session/Paymentbatch_id) have no ondelete, 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 by unenroll before deleting. No destructive cascade.
  3. No feedback on any mutation button. → Wrapped delete / remove / unenroll / deactivate / disable handlers in try/catch with success/error toasts (the toast system already existed and was used by other pages).

Files

  • frontend/src/api.js204null
  • backend/app/routers/batches.py — 409 guard + dead-row cleanup
  • frontend/src/pages/{Batches,Tutors,Users,StudentDetail}.jsx — toast feedback

Verification (Docker + Playwright)

  • 🔴 Delete batch with a student → red "Can't delete: batch still has 1 enrolled student(s)…" toast, card stays, HTTP 409 (not 500)
  • 🟢 Remove student → "Student removed." toast
  • 🟢 Delete now-empty batch → "Batch deleted." toast, card disappears, HTTP 204
  • Create flows unregressed (8/8)

🤖 Generated with Claude Code

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>
@CaptainCo0L CaptainCo0L merged commit db2ac79 into main Jun 29, 2026
1 check passed
@CaptainCo0L CaptainCo0L deleted the fix-delete-feedback branch June 29, 2026 07:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant