diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2015-05-15 12:35:21 -0400 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2015-05-15 12:38:28 -0400 |
commit | d178707ecaeb547470e2b7b37b9a939abc69cbd0 (patch) | |
tree | dc4b674748cf673a123b90797c3525c3a13ef657 /lib/sqlalchemy/exc.py | |
parent | 64c1f2e5688879e1cc087f4e4a893d32267fd1fb (diff) | |
download | sqlalchemy-d178707ecaeb547470e2b7b37b9a939abc69cbd0.tar.gz |
- Added support for the case of the misbehaving DBAPI that has
pep-249 exception names linked to exception classes of an entirely
different name, preventing SQLAlchemy's own exception wrapping from
wrapping the error appropriately.
The SQLAlchemy dialect in use needs to implement a new
accessor :attr:`.DefaultDialect.dbapi_exception_translation_map`
to support this feature; this is implemented now for the py-postgresql
dialect.
fixes #3421
Diffstat (limited to 'lib/sqlalchemy/exc.py')
-rw-r--r-- | lib/sqlalchemy/exc.py | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/lib/sqlalchemy/exc.py b/lib/sqlalchemy/exc.py index 9b27436b3..3a4f346e0 100644 --- a/lib/sqlalchemy/exc.py +++ b/lib/sqlalchemy/exc.py @@ -13,8 +13,6 @@ raised as a result of DBAPI exceptions are all subclasses of """ -import traceback - class SQLAlchemyError(Exception): """Generic error class.""" @@ -278,7 +276,8 @@ class DBAPIError(StatementError): @classmethod def instance(cls, statement, params, orig, dbapi_base_err, - connection_invalidated=False): + connection_invalidated=False, + dialect=None): # Don't ever wrap these, just return them directly as if # DBAPIError didn't exist. if (isinstance(orig, BaseException) and @@ -300,6 +299,9 @@ class DBAPIError(StatementError): glob = globals() for super_ in orig.__class__.__mro__: name = super_.__name__ + if dialect: + name = dialect.dbapi_exception_translation_map.get( + name, name) if name in glob and issubclass(glob[name], DBAPIError): cls = glob[name] break |