diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2017-07-14 18:06:48 -0400 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2017-08-25 16:12:30 -0400 |
| commit | f87069a3b0e9c2d79eced81a0326a9a904106dc6 (patch) | |
| tree | 6a5fb58ff0c92af3c3ebcd0af9c5c954fde43864 /lib/sqlalchemy/engine | |
| parent | 887fb3ebaad20847edc752f5fcf072ace947d56a (diff) | |
| download | sqlalchemy-f87069a3b0e9c2d79eced81a0326a9a904106dc6.tar.gz | |
Don't do recovery operations under Empty/AttributeError
Made some adjustments to :class:`.Pool` and :class:`.Connection` such
that recovery logic is not run underneath exception catches for
``pool.Empty``, ``AttributeError``, since when the recovery operation
itself fails, Python 3 creates a misleading stack trace referring to the
``Empty`` / ``AttributeError`` as the cause, when in fact these exception
catches are part of control flow.
Change-Id: Id3ed9a8f96ce4ccb4009c94af30ddc2ddb9818b9
Fixes: #4028
Diffstat (limited to 'lib/sqlalchemy/engine')
| -rw-r--r-- | lib/sqlalchemy/engine/base.py | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/lib/sqlalchemy/engine/base.py b/lib/sqlalchemy/engine/base.py index 91f4493c2..b5c95cb17 100644 --- a/lib/sqlalchemy/engine/base.py +++ b/lib/sqlalchemy/engine/base.py @@ -345,10 +345,13 @@ class Connection(Connectable): try: return self.__connection except AttributeError: - try: - return self._revalidate_connection() - except BaseException as e: - self._handle_dbapi_exception(e, None, None, None, None) + # escape "except AttributeError" before revalidating + # to prevent misleading stacktraces in Py3K + pass + try: + return self._revalidate_connection() + except BaseException as e: + self._handle_dbapi_exception(e, None, None, None, None) def get_isolation_level(self): """Return the current isolation level assigned to this @@ -962,6 +965,10 @@ class Connection(Connectable): try: conn = self.__connection except AttributeError: + # escape "except AttributeError" before revalidating + # to prevent misleading stacktraces in Py3K + conn = None + if conn is None: conn = self._revalidate_connection() dialect = self.dialect @@ -1111,6 +1118,10 @@ class Connection(Connectable): try: conn = self.__connection except AttributeError: + # escape "except AttributeError" before revalidating + # to prevent misleading stacktraces in Py3K + conn = None + if conn is None: conn = self._revalidate_connection() context = constructor(dialect, self, conn, *args) |
