feat: sqlite integrity error handle
This commit is contained in:
parent
da8917869f
commit
b2e5dd2ebb
2 changed files with 7 additions and 1 deletions
|
|
@ -100,7 +100,10 @@ async def create_group(db: db_dependency, org_model: org_model_root_claim_body_d
|
|||
try:
|
||||
db.flush()
|
||||
except IntegrityError as e:
|
||||
if isinstance(e.orig, errors.UniqueViolation):
|
||||
if (
|
||||
getattr(e.orig, "pgcode", None) == "23505" # Postgres unique violation
|
||||
or "UNIQUE constraint failed" in str(e.orig) # SQLite unique violation
|
||||
):
|
||||
raise ConflictException("Group with this name already exists")
|
||||
response = GroupSchema(**group_model.__dict__)
|
||||
db.commit()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue