@contextmanager
def context_session(self) -> Iterator[SqlSession]:
    'Override base method to include exception handling.'
    try:
        (yield from self.get_db())
    except sa.exc.StatementError as e:
        if isinstance(e.orig, psycopg2.errors.UniqueViolation):
            raise errors.ConflictError('resource already exists') from e
        elif isinstance(e.orig, psycopg2.errors.ForeignKeyViolation):
            raise errors.ForeignKeyError('collection does not exist') from e
        logger.error(e, exc_info=True)
        raise errors.DatabaseError('unhandled database error')
Override base method to include exception handling.
@contextmanager
def context_session(self) -> Iterator[SqlSession]:
    
    try:
        (yield from self.get_db())
    except sa.exc.StatementError as e:
        if isinstance(e.orig, psycopg2.errors.UniqueViolation):
            raise errors.ConflictError('resource already exists') from e
        elif isinstance(e.orig, psycopg2.errors.ForeignKeyViolation):
            raise errors.ForeignKeyError('collection does not exist') from e
        logger.error(e, exc_info=True)
        raise errors.DatabaseError('unhandled database error')