summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/dialects/postgresql/pypostgresql.py
diff options
context:
space:
mode:
Diffstat (limited to 'lib/sqlalchemy/dialects/postgresql/pypostgresql.py')
-rw-r--r--lib/sqlalchemy/dialects/postgresql/pypostgresql.py17
1 files changed, 17 insertions, 0 deletions
diff --git a/lib/sqlalchemy/dialects/postgresql/pypostgresql.py b/lib/sqlalchemy/dialects/postgresql/pypostgresql.py
index 00c67d170..db6d5e16c 100644
--- a/lib/sqlalchemy/dialects/postgresql/pypostgresql.py
+++ b/lib/sqlalchemy/dialects/postgresql/pypostgresql.py
@@ -65,6 +65,23 @@ class PGDialect_pypostgresql(PGDialect):
from postgresql.driver import dbapi20
return dbapi20
+ _DBAPI_ERROR_NAMES = [
+ "Error",
+ "InterfaceError", "DatabaseError", "DataError",
+ "OperationalError", "IntegrityError", "InternalError",
+ "ProgrammingError", "NotSupportedError"
+ ]
+
+ @util.memoized_property
+ def dbapi_exception_translation_map(self):
+ if self.dbapi is None:
+ return {}
+
+ return dict(
+ (getattr(self.dbapi, name).__name__, name)
+ for name in self._DBAPI_ERROR_NAMES
+ )
+
def create_connect_args(self, url):
opts = url.translate_connect_args(username='user')
if 'port' in opts: