feat: all unique constraints tested

This commit is contained in:
Chris Milne 2026-06-08 16:05:20 +01:00
parent 52990aae13
commit e9b272811f
7 changed files with 28 additions and 11 deletions

View file

@ -20,7 +20,6 @@ from typing import Annotated
from fastapi import APIRouter, status
from fastapi.params import Query
from psycopg.errors import UniqueViolation
from sqlalchemy.exc import IntegrityError
from src.contact.schemas import ContactModel
@ -143,7 +142,10 @@ async def create_org(
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="Organisation with this name already exists"
)