summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/engine/base.py
diff options
context:
space:
mode:
Diffstat (limited to 'lib/sqlalchemy/engine/base.py')
-rw-r--r--lib/sqlalchemy/engine/base.py13
1 files changed, 10 insertions, 3 deletions
diff --git a/lib/sqlalchemy/engine/base.py b/lib/sqlalchemy/engine/base.py
index bb3b82eea..997991b30 100644
--- a/lib/sqlalchemy/engine/base.py
+++ b/lib/sqlalchemy/engine/base.py
@@ -507,7 +507,8 @@ class Connection(Connectable):
except Exception as e:
self._handle_dbapi_exception(e, None, None, None, None)
finally:
- if self.connection._reset_agent is self.__transaction:
+ if not self.__invalid and \
+ self.connection._reset_agent is self.__transaction:
self.connection._reset_agent = None
self.__transaction = None
else:
@@ -524,7 +525,8 @@ class Connection(Connectable):
except Exception as e:
self._handle_dbapi_exception(e, None, None, None, None)
finally:
- if self.connection._reset_agent is self.__transaction:
+ if not self.__invalid and \
+ self.connection._reset_agent is self.__transaction:
self.connection._reset_agent = None
self.__transaction = None
@@ -637,7 +639,12 @@ class Connection(Connectable):
conn.close()
if conn._reset_agent is self.__transaction:
conn._reset_agent = None
- del self.__connection
+
+ # the close() process can end up invalidating us,
+ # as the pool will call our transaction as the "reset_agent"
+ # for rollback(), which can then cause an invalidation
+ if not self.__invalid:
+ del self.__connection
self.__can_reconnect = False
self.__transaction = None