Skip to content

fix: duplicate keys when provisioning access to accounts #610

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

Merged
merged 4 commits into from
Jul 18, 2025

Conversation

rohan-chaturvedi
Copy link
Member

@rohan-chaturvedi rohan-chaturvedi commented Jul 18, 2025

🔍 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 + env EnvironmentKey objects. This causes users to see the Get() 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

  • Add a client-side loading state that disables the button on first click
  • Add a model-level unique constrain that prevents duplicate objects from being created

🖼️ 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 error

  • Checkout 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...

  • Ensure linting passes (code style checks)?
    - [ ] Update dependencies and lockfiles (if required)
  • Update migrations (if required)
    - [ ] Regenerate graphql schema and types (if required)
  • Verify the app builds locally?
  • Manually test the changes on different browsers/devices?

@rohan-chaturvedi rohan-chaturvedi added bug Something isn't working frontend Change in frontend code backend updates migrations This PR adds new migrations that update the database schema labels Jul 18, 2025
nimish-ks
nimish-ks previously approved these changes Jul 18, 2025
@rohan-chaturvedi rohan-chaturvedi merged commit 476e11b into main Jul 18, 2025
7 checks passed
@rohan-chaturvedi rohan-chaturvedi deleted the fix--add-app-access-duplicate-keys branch July 18, 2025 09:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend bug Something isn't working frontend Change in frontend code updates migrations This PR adds new migrations that update the database schema
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants