GLM-5.3 Flash · Balanced
fix-proper-handling-of-group-memberships-discourse-cursor
Discourse · Ruby · L · 300–799 lines · 6 files
The normal review, with one generalist agent. Judge: Claude Opus 5.5.
- Gold bugs found
- 3 of 13
- Comments published
- 4
- Comments matching a bug
- 3
- Comments not matching
- 1
- Cost of this PR
- $0.090
Published comments (4)
add_members raises RecordNotUnique when re-adding an existing member — Resubmitting a username that is already a member hits the unique index on `group_users` and raises an unhandled `ActiveRecord::RecordNotUnique`, a likely case since the admin UI never clears its input (admin-group.js.es6). Skip users already in the group before calling `Group#add`, or reuse the diff-based `usernames=` setter.
`automatic` resolves against member, remove link shows for automatic groups — Clicking the remove link sends a DELETE the server rejects with 422 `can_not_modify_automatic`, and `Group#removeMember` swallows the failure with only `.then`. Bind the group's `automatic` flag into the item view instead of the bare `automatic` lookup.
Unbounded limit/offset params cause 500 errors and empty results in members — `?limit=-1` or `?offset=-5` make PostgreSQL reject the query with a 500, and `limit=0` returns an empty member list — previously only automatic groups accepted these params, so this now hits every group. Clamp `limit` and floor `offset` at 0.
remove_member bypasses GroupUser destroy, leaving user_count stale — The raw `group.users.delete` bypasses `GroupUser#destroy`, so the counter cache never decrements and the stored `user_count` shown by `BasicGroupSerializer` and admin pagination stays too high for custom groups. Use `Group#remove`, which destroys the `GroupUser` rows and lets the counter cache update.