-
Breaking it down:
Backend —
BranchService.deleteBranch()pre-delete check ~30 min — simple query + exception with messageBackend —
ProjectService.deleteProject()cascade order fix ~1 hour — need to trace the full dependency chain, make sure comments, review requests, and any other PR children are handled before PRs, before branchesBackend —
GlobalExceptionHandlermeaningful FK message ~20 min — pattern match on constraint name or exception type, return 400 with clean messageFrontend — surface the 400 message in the toast ~15 min — if the frontend is already reading the error message from the response body this may be free
Testing ~30 min — verify branch delete blocked cleanly, verify project with PRs deletes successfully, run regression script
Total: ~2.5 hours
The cascade fix is the riskiest part — worth having Joan eyeball the migration/cascade order before you commit it, since touching deletion order on core entities is the kind of thing that can have unexpected side effects on other FK chains you haven't hit yet.
-
Root Cause
Service layer deletion order does not account for the FK dependency chain. Branch deletion does not check for dependent PRs before attempting delete. Project deletion cascade does not delete PRs before branches.
Fix
Branch deletion
Add a pre-delete check in
BranchService.deleteBranch():- Query
pull_requesttable for any PR referencing this branch as source or target - If found, return
400with message:"Cannot delete branch — it has an associated pull request"
Project deletion
Fix cascade order in
ProjectService.deleteProject():- Delete PR comments
- Delete PRs
- Delete branches
- Delete issues
- Delete project
Error handling
Update
GlobalExceptionHandlerto return a meaningful message for FK constraint violations rather than a generic 500. - Query
-
rksuma@Ramakrishnans-MacBook-Pro sztab % git checkout release/1.10.0 git checkout -b fix/SZ-126-deletion-cascade Switched to branch 'release/1.10.0' Your branch is up to date with 'origin/release/1.10.0'. Switched to a new branch 'fix/SZ-126-deletion-cascade' rksuma@Ramakrishnans-MacBook-Pro sztab % -
| Type |
Bug
|
| Priority |
Blocker
|
| Assignee | |
| Version |
1.10.0
|
| Sprints |
n/a
|
| Customer |
n/a
|
Summary
Deleting a branch or project that has associated pull requests fails with a database foreign key constraint violation. The UI surfaces a vague "Unexpected error" toast with no actionable guidance. Any project that has ever had a PR cannot be deleted from the UI.
Steps to Reproduce
Branch deletion
Project deletion
Expected Behavior
Actual Behavior
DataIntegrityViolationExceptionon FK constraintfk89ifjey7w4brx0orv0drofon4(pull_request → branches)GlobalExceptionHandlercatches it and returns generic 500