[Regression] Project/branch deletion blocked by PR foreign key constraint (SZ-126)
rk@tigase.net opened 5 days ago

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

  1. Create a project with a local repository
  2. Create a branch
  3. Open a pull request from that branch
  4. Navigate to Branches tab
  5. Click delete on the branch with the PR badge

Project deletion

  1. Any project that has at least one PR (open or closed)
  2. Attempt to delete the project from project settings

Expected Behavior

  • Branch deletion: Block with clear message — "Cannot delete branch — it has an associated pull request. Close or merge the PR first."
  • Project deletion: Cascade deletions in correct FK-safe order: PR comments → PRs → branches → issues → project

Actual Behavior

  • Backend throws DataIntegrityViolationException on FK constraint fk89ifjey7w4brx0orv0drofon4 (pull_request → branches)
  • GlobalExceptionHandler catches it and returns generic 500
  • UI displays "Unexpected error while deleting branch"
  • Project cannot be deleted at all from the UI
  • rk@tigase.net commented 5 days ago

    Breaking it down:

    Backend — BranchService.deleteBranch() pre-delete check ~30 min — simple query + exception with message

    Backend — 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 branches

    Backend — GlobalExceptionHandler meaningful FK message ~20 min — pattern match on constraint name or exception type, return 400 with clean message

    Frontend — 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.

  • rk@tigase.net changed title 5 days ago
    Previous Value Current Value
    Project/branch deletion blocked by PR foreign key constraint
    [Regression] Project/branch deletion blocked by PR foreign key constraint
  • rk@tigase.net commented 5 days ago

    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_request table for any PR referencing this branch as source or target
    • If found, return 400 with message: "Cannot delete branch — it has an associated pull request"

    Project deletion

    Fix cascade order in ProjectService.deleteProject():

    1. Delete PR comments
    2. Delete PRs
    3. Delete branches
    4. Delete issues
    5. Delete project

    Error handling

    Update GlobalExceptionHandler to return a meaningful message for FK constraint violations rather than a generic 500.

  • rk@tigase.net commented 4 days ago
    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 % 
    
    
  • rk@tigase.net changed state to 'In Progress' 4 days ago
    Previous Value Current Value
    Open
    In Progress
  • rk@tigase.net commented 3 days ago

    Merged into release/1.10.0

  • rk@tigase.net changed state to 'Pending approval' 3 days ago
    Previous Value Current Value
    In Progress
    Pending approval
  • rk@tigase.net referenced from other issue 3 days ago
  • rk@tigase.net commented 4 hours ago

    Fix merged into wolsonsc

  • rk@tigase.net changed state to 'Closed' 4 hours ago
    Previous Value Current Value
    Pending approval
    Closed
issue 1 of 1
Type
Bug
Priority
Blocker
Assignee
Version
1.10.0
Sprints
n/a
Customer
n/a
Issue Votes (1)
Watchers (3)
Reference
SZ-126
Please wait...
Page is in error, reload to recover