Skip to content

Commit 349c2dc

Browse files
committed
adds missing errors file
1 parent 969bbb3 commit 349c2dc

File tree

1 file changed

+61
-0
lines changed
  • packages/postgres-database/src/simcore_postgres_database

1 file changed

+61
-0
lines changed
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
""" aiopg errors
2+
3+
StandardError
4+
|__ Warning
5+
|__ Error
6+
|__ InterfaceError
7+
|__ DatabaseError
8+
|__ DataError
9+
|__ OperationalError
10+
|__ IntegrityError
11+
|__ InternalError
12+
|__ ProgrammingError
13+
|__ NotSupportedError
14+
15+
- aiopg reuses DBAPI exceptions
16+
SEE https://aiopg.readthedocs.io/en/stable/core.html?highlight=Exception#exceptions
17+
SEE http://initd.org/psycopg/docs/module.html#dbapi-exceptions
18+
"""
19+
# NOTE: psycopg2.errors are created dynamically
20+
# pylint: disable=no-name-in-module
21+
22+
from typing import Tuple
23+
24+
from psycopg2 import DatabaseError, DataError
25+
from psycopg2 import Error as DBAPIError
26+
from psycopg2 import (
27+
IntegrityError,
28+
InterfaceError,
29+
InternalError,
30+
NotSupportedError,
31+
OperationalError,
32+
ProgrammingError,
33+
)
34+
from psycopg2.errors import ForeignKeyViolation, NotNullViolation, UniqueViolation
35+
36+
assert issubclass(UniqueViolation, IntegrityError) # nosec
37+
38+
# TODO: see https://stackoverflow.com/questions/58740043/how-do-i-catch-a-psycopg2-errors-uniqueviolation-error-in-a-python-flask-app
39+
# from sqlalchemy.exc import IntegrityError
40+
#
41+
# from psycopg2.errors import UniqueViolation
42+
#
43+
# try:
44+
# s.commit()
45+
# except IntegrityError as e:
46+
# assert isinstance(e.orig, UniqueViolation)
47+
48+
49+
__all__: Tuple[str, ...] = (
50+
"DatabaseError",
51+
"DataError",
52+
"DBAPIError",
53+
"ForeignKeyViolation",
54+
"IntegrityError",
55+
"InterfaceError",
56+
"InternalError",
57+
"NotNullViolation",
58+
"NotSupportedError",
59+
"OperationalError",
60+
"ProgrammingError",
61+
)

0 commit comments

Comments
 (0)