fix: duplicate keys when provisioning access to accounts #610
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.
🔍 Overview
When provisioning access for a user or service account to an app, it is possible to rapidly 'burst' click the 'Add' button, resulting in multiple mutations to the backend that are processed concurrently with
update_or_create
and create duplicate account + envEnvironmentKey
objects. This causes users to see theGet() returned more than one environment key
error and effectively locks them out of the App, since the query resolvers expect one one such object to every exist.💡 Proposed Changes
🖼️ Screenshots or Demo
app-access-loading-state-1752827557923.mp4
📝 Release Notes
Fixed a bug that caused duplicate
EnvironmentKey
objects to be created for an account➕ Additional Context
This PR also includes a data migration that cleans up existing duplicates before the constraint is applied.
✨ How to Test the Changes Locally
Checkout to main
Navigate to App > Access > Members
Click "Add members"
Select an account (User B) and all envs (more envs make this easier to reproduce)
Rapidly click the "Add" button 3-5 times
Notice that multiple toasts are created
Attempt to open the app as a the user who was added
Notice the
Get() returned more than one environment key
errorCheckout to this branch
Run the migrations
Start the Console
Notice that the app is now accessible by User B
Remove them from the app and try the previous steps again, attempting to burst click the "Add" button
Verify that no multiple toasts or mutations are triggered
Verify that User B can access the app and assigned Envs
💚 Did You...
- [ ] Update dependencies and lockfiles (if required)- [ ] Regenerate graphql schema and types (if required)