diff options
Diffstat (limited to 'lib/sqlalchemy')
-rw-r--r-- | lib/sqlalchemy/engine/base.py | 2 | ||||
-rw-r--r-- | lib/sqlalchemy/pool.py | 7 |
2 files changed, 6 insertions, 3 deletions
diff --git a/lib/sqlalchemy/engine/base.py b/lib/sqlalchemy/engine/base.py index 6e1564c34..9f656cac8 100644 --- a/lib/sqlalchemy/engine/base.py +++ b/lib/sqlalchemy/engine/base.py @@ -1115,8 +1115,8 @@ class Connection(Connectable): if self._is_disconnect: del self._is_disconnect dbapi_conn_wrapper = self.connection + self.engine.pool._invalidate(dbapi_conn_wrapper, e) self.invalidate(e) - self.engine.pool._invalidate(dbapi_conn_wrapper) if self.should_close_with_result: self.close() diff --git a/lib/sqlalchemy/pool.py b/lib/sqlalchemy/pool.py index 7fc4fc659..799443546 100644 --- a/lib/sqlalchemy/pool.py +++ b/lib/sqlalchemy/pool.py @@ -277,7 +277,7 @@ class Pool(log.Identified): return _ConnectionRecord(self) - def _invalidate(self, connection): + def _invalidate(self, connection, exception=None): """Mark all connections established within the generation of the given connection as invalidated. @@ -291,6 +291,8 @@ class Pool(log.Identified): rec = getattr(connection, "_connection_record", None) if not rec or self._invalidate_time < rec.starttime: self._invalidate_time = time.time() + if getattr(connection, 'is_valid', False): + connection.invalidate(exception) def recreate(self): @@ -733,7 +735,8 @@ class _ConnectionFairy(object): """ if self.connection is None: - raise exc.InvalidRequestError("This connection is closed") + util.warn("Can't invalidate an already-closed connection.") + return if self._connection_record: self._connection_record.invalidate(e=e) self.connection = None |