[codex] fix stale group bindings when deleting via GroupService#1760
Open
Soliyakeitong wants to merge 1 commit intoWei-Shaw:mainfrom
Open
[codex] fix stale group bindings when deleting via GroupService#1760Soliyakeitong wants to merge 1 commit intoWei-Shaw:mainfrom
Soliyakeitong wants to merge 1 commit intoWei-Shaw:mainfrom
Conversation
1e0d466 to
4d0483f
Compare
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.
What changed
GroupService.DeletethroughDeleteCascadeinstead of the plain soft-delete pathGroupService.Deletemust use cascade cleanup semanticsWhy
We found two deletion paths for groups with different behavior:
adminService.DeleteGroupalready usesDeleteCascadeGroupService.Deleteonly soft-deleted thegroupsrowThat second path can leave stale
account_groupsbindings behind if any caller deletes a group throughGroupService.Delete. In production, this presents as accounts still appearing bound to a deleted group, which breaks group counts and makes "ungrouped" filtering misleading.Root cause
groupRepo.Deleteonly soft-deletes the group record, whilegroupRepo.DeleteCascadealso clears dependent relations such as:account_groupsgroup_iduser_allowed_groupsGroupService.Deletewas calling the non-cascading repository method.Validation
go test -tags unit ./internal/service -run '^TestGroupService_Delete_UsesDeleteCascade$|^TestAdminService_DeleteGroup_'Impact
This makes the non-admin delete service consistent with the admin delete path and prevents deleted groups from leaving orphaned account-group bindings behind.