Handle DuplicateKeyError on org rename requests (#514)

* Handle DuplicateKeyError on org rename requests
This commit is contained in:
Tessa Walsh 2023-01-25 20:46:35 -05:00 committed by GitHub
parent 9f0abd6a28
commit 231c37108c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -407,7 +407,11 @@ def init_orgs_api(app, mdb, user_manager, invites, user_dep: User):
org: Organization = Depends(org_owner_dep), org: Organization = Depends(org_owner_dep),
): ):
org.name = rename.name org.name = rename.name
await ops.update(org) try:
await ops.update(org)
except DuplicateKeyError:
# pylint: disable=raise-missing-from
raise HTTPException(status_code=400, detail="duplicate_org_name")
return {"updated": True} return {"updated": True}