Improve FK constraint violation error messages for Project/ResourceGroup deletion
- Dominant language
- Python
- Stars
- 670
- Forks
- 183
- Avg merge
- 17h 7m
- Merged PRs (30d)
- 358
Description
## Summary
When deleting a Project or Resource Group fails due to FK constraint violations, provide human-friendly error messages that explain exactly which entities are blocking the deletion.
## Current Behavior
- Deletion fails with generic `IntegrityError` or custom errors like `ProjectHasActiveKernelsError`
- Users don't know how many or which types of entities are blocking deletion
## Expected Behavior
Provide detailed error messages like:
```
Cannot delete project "my-project":
- 5 active sessions
- 12 vfolders
- 2 endpoints
- 3 model service routings
are referencing this project. Please remove or reassign these resources first.
```
## Scope
### For GroupRow (Projects)
- Check and report counts for: sessions, kernels, vfolders, endpoints, routings, networks, session_templates, container_registry associations
### For ScalingGroupRow (Resource Groups)
- Check and report counts for: sessions, kernels, agents, endpoints
## Technical Approach
1. Create `DeletionBlocker` dataclass to hold blocker info (entity_type, count, is_active)
1. Implement `_collect_deletion_blockers()` method in AdminGroupRepository
1. Implement similar method in ScalingGroupDBSource
1. Return structured error with all blockers listed
1. Format error message in service layer for API response
## Acceptance Criteria
- [ ] Deletion error messages list all blocking entity types with counts
- [ ] Active vs inactive entities are distinguished in the message
- [ ] Error message suggests actionable next steps
- [ ] Works for both Project and Resource Group deletion
JIRA Issue: BA-3710
Contributor guide
Assessment
This issue has not been assessed yet.