Flagsmith / flagsmith

Open Source Feature Flagging and Remote Config Service. Host on-prem or use our hosted version at https://flagsmith.com/
https://flagsmith.com/
BSD 3-Clause "New" or "Revised" License
4.94k stars 375 forks source link

Recreating an environment with the same key #3060

Open evantissot opened 1 year ago

evantissot commented 1 year ago

Describe the bug I don't know if it is a feature or a bug since I guess environment key should be generated randomly. When deleting an environment, and then creating a new one with the same environment key. I get the following error duplicate key value violates unique constraint "environments_environment_api_key_key"

To Reproduce

Steps to reproduce the behavior:

  1. Create an environment with an
curl --request POST \
  --url https://flagsmith-api.mybrand.com/api/v1/environments/\
  --header 'Authorization: Token myToken' \
  --header 'Content-Type: application/json' \
  --data '{
    "name": "myEnv",
    "api_key": "deadBeef",
    "project": "1"
}'
  1. Delete it (via API, or UI)
  2. Create a new environment with the previous command

Expected behavior After running the 3 commands, the environment is available. I think this can be achievable with different options:

How are you running Flagsmith?

Additional context Running version 2.83.0

matthewelwell commented 1 year ago

Thanks for this @evantissot. We'd be happy to receive a PR for this if you're willing to do so.

gagantrivedi commented 11 months ago

The environment table is one of our busiest tables. Altering a constraint on that table will be non-trivial. Therefore, removing the good first issue tag from this.