-
Notifications
You must be signed in to change notification settings - Fork 205
Add batch of members endpoints to fix race conditions (#2760) #2779
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add batch of members endpoints to fix race conditions (#2760) #2779
Conversation
|
Why not allow adding/removing a batch of users? |
5aa6f22 to
95d076d
Compare
|
One more thought: One this is done, we can also add UI via a separate PR. |
e89a648 to
146cce7
Compare
f00e467 to
5ca77f9
Compare
437899b to
806c095
Compare
|
Is this PR a part of #2795? If so, should it be closed? |
948c5e4 to
f15435f
Compare
f15435f to
2d5ce9e
Compare
|
@r4victor please confirm if this is good to merge |
|
@haydnli-shopify Since we merged #2795, this PR can be closed, right? |
Yes, i will close it! |
Summary
Implements atomic single and batch member management endpoints to eliminate race conditions when multiple automations add/remove project members simultaneously. The existing
set_membersendpoint required passing an authoritative list of all members, creating race conditions in concurrent scenarios.This PR enhances the member management system to support both single-user and batch operations through the same endpoints, providing flexibility for different use cases while maintaining backwards compatibility.
Fixes #2684 (parent ticket #2742)
Changes Made
AddProjectMemberRequestto accept single member or array of membersRemoveProjectMemberRequestto accept single username or array of usernamesadd_project_members()andremove_project_members()service functions supporting both single and batch operationsPOST /api/projects/{project_name}/add_memberendpoint for single/batch operationsPOST /api/projects/{project_name}/remove_memberendpoint for single/batch operationsProjectsAPIClientwith backwards-compatible methods and new batch methodsAPI Usage
Add a single member
POST /api/projects/my-project/add_memberBody:
{ "members": { "username": "john@example.com", "project_role": "user" } }Add multiple members (batch)
POST /api/projects/my-project/add_memberBody:
{ "members": [ {"username": "john@example.com", "project_role": "user"}, {"username": "jane_doe", "project_role": "manager"}, {"username": "alice", "project_role": "user"} ] }Remove a single member
POST /api/projects/my-project/remove_memberBody:
{ "usernames": "john_doe" }Remove multiple members (batch)
POST /api/projects/my-project/remove_memberBody:
{ "usernames": ["john_doe", "jane@example.com", "alice"] }Update existing member role (via add_member)
POST /api/projects/my-project/add_memberBody:
{ "members": { "username": "jane", "project_role": "admin" } }Race Condition Fix
Previously, concurrent automations had to read and rewrite the entire project member list using the
set_membersendpoint, which led to race conditions and unintended overwrites. This PR introduces atomicadd_memberandremove_memberoperations that support both single and batch operations, allowing changes to apply independently and safely—even when triggered simultaneously.