Skip to content

Commit

Permalink
detect unique violation for psycopg
Browse files Browse the repository at this point in the history
  • Loading branch information
simonbohnen committed Oct 28, 2022
1 parent c0dec1f commit 7c7303b
Showing 1 changed file with 2 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ def _create(
db.commit()
except IntegrityError as e:
db.rollback()
if "UNIQUE constraint failed: credentials.username" in str(e):
if "unique" in str(e).lower() and "INSERT INTO credentials" in str(e):
# This detection should work for both psycopg2 and sqlite3
raise HTTPException(
status_code=status.HTTP_409_CONFLICT,
detail=f"""
Expand Down

0 comments on commit 7c7303b

Please sign in to comment.