feat: all unique constraints tested
This commit is contained in:
parent
52990aae13
commit
e9b272811f
7 changed files with 28 additions and 11 deletions
|
|
@ -9,7 +9,6 @@ Endpoints:
|
|||
"""
|
||||
|
||||
from fastapi import APIRouter, status
|
||||
from psycopg.errors import UniqueViolation
|
||||
from sqlalchemy.exc import IntegrityError
|
||||
|
||||
from src.exceptions import ConflictException
|
||||
|
|
@ -87,7 +86,10 @@ async def register_service(
|
|||
try:
|
||||
db.flush()
|
||||
except IntegrityError as e:
|
||||
if isinstance(e.orig, UniqueViolation):
|
||||
if (
|
||||
getattr(e.orig, "pgcode", None) == "23505" # Postgres unique violation
|
||||
or "UNIQUE constraint failed" in str(e.orig) # SQLite unique violation
|
||||
):
|
||||
raise ConflictException(message="Service with this name already exists")
|
||||
response = ServiceWithKeySchema(**service_model.__dict__)
|
||||
db.commit()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue