Add batch of members endpoints to fix race conditions (#2760)#2779
Closed
haydnli-shopify wants to merge 15 commits intodstackai:masterfrom
Closed
Add batch of members endpoints to fix race conditions (#2760)#2779haydnli-shopify wants to merge 15 commits intodstackai:masterfrom
haydnli-shopify wants to merge 15 commits intodstackai:masterfrom
Conversation
Contributor
|
Why not allow adding/removing a batch of users? |
5aa6f22 to
95d076d
Compare
colinjc
reviewed
Jun 9, 2025
Contributor
|
One more thought: One this is done, we can also add UI via a separate PR. |
e89a648 to
146cce7
Compare
Merged
dakota-shop
reviewed
Jun 11, 2025
f00e467 to
5ca77f9
Compare
437899b to
806c095
Compare
Contributor
Author
r4victor
reviewed
Jun 17, 2025
r4victor
reviewed
Jun 17, 2025
r4victor
reviewed
Jun 17, 2025
r4victor
reviewed
Jun 17, 2025
r4victor
reviewed
Jun 17, 2025
Contributor
|
Is this PR a part of #2795? If so, should it be closed? |
Contributor
Author
948c5e4 to
f15435f
Compare
f15435f to
2d5ce9e
Compare
Contributor
|
@r4victor please confirm if this is good to merge |
r4victor
reviewed
Jun 25, 2025
Contributor
|
@haydnli-shopify Since we merged #2795, this PR can be closed, right? |
Contributor
Author
Yes, i will close it! |
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.
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.