Flagsmith / Flagsmith/flagsmith
Recreating an environment with the same key
- Dominant language
- Python
- Stars
- 6.6k
- Forks
- 567
- Avg merge
- 1d 13h
- Merged PRs (30d)
- 121
Description
**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"
}'
```
2. Delete it (via API, or UI)
3. 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:
- A new env is created (but the unique constraint on the env key has to be changed...)
- The env is restored (via the soft delete record)
**How are you running Flagsmith?**
- [ ] Self Hosted with Docker
- [X] Self Hosted with Kubernetes
- [ ] SaaS at flagsmith.com
- [ ] Some other way
**Additional context**
Running version 2.83.0
Contributor guide
Assessment
This issue has not been assessed yet.