From f87069a3b0e9c2d79eced81a0326a9a904106dc6 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Fri, 14 Jul 2017 18:06:48 -0400 Subject: 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 --- lib/sqlalchemy/engine/base.py | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) (limited to 'lib/sqlalchemy/engine') 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) -- cgit v1.2.1