summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/events.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2016-09-21 15:37:20 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2016-09-21 18:39:31 -0400
commit7827dfb6726a682c630d66b24423582d5dc09589 (patch)
tree924c2abdb48154bbc36f09c9c4575a69873414e4 /lib/sqlalchemy/events.py
parent930b07c3af5300e65473d44535db8c1d7133cb13 (diff)
downloadsqlalchemy-7827dfb6726a682c630d66b24423582d5dc09589.tar.gz
Handle BaseException in all _handle_dbapi_error
Tests illustrate that exceptions like GreenletExit and even KeyboardInterrupt can corrupt the state of a DBAPI connection like that of pymysql and mysqlclient. Intercept BaseException errors within the handle_error scheme and invalidate just the connection alone in this case, but not the whole pool. The change is backwards-incompatible with a program that currently intercepts ctrl-C within a database transaction and wants to continue working on that transaction. Ensure the event hook can be used to reverse this behavior. Change-Id: Ifaa013c13826d123eef34e32b7e79fff74f1b21b Fixes: #3803
Diffstat (limited to 'lib/sqlalchemy/events.py')
-rw-r--r--lib/sqlalchemy/events.py10
1 files changed, 10 insertions, 0 deletions
diff --git a/lib/sqlalchemy/events.py b/lib/sqlalchemy/events.py
index e99c5b5e5..8776f6562 100644
--- a/lib/sqlalchemy/events.py
+++ b/lib/sqlalchemy/events.py
@@ -741,6 +741,9 @@ class ConnectionEvents(event.Events):
* read-only, low-level exception handling for logging and
debugging purposes
* exception re-writing
+ * Establishing or disabling whether a connection or the owning
+ connection pool is invalidated or expired in response to a
+ specific exception.
The hook is called while the cursor from the failed operation
(if any) is still open and accessible. Special cleanup operations
@@ -806,6 +809,13 @@ class ConnectionEvents(event.Events):
.. versionadded:: 0.9.7 Added the
:meth:`.ConnectionEvents.handle_error` hook.
+ .. versionchanged:: 1.1 The :meth:`.handle_error` event will now
+ receive all exceptions that inherit from ``BaseException``, including
+ ``SystemExit`` and ``KeyboardInterrupt``. The setting for
+ :attr:`.ExceptionContext.is_disconnect` is ``True`` in this case
+ and the default for :attr:`.ExceptionContext.invalidate_pool_on_disconnect`
+ is ``False``.
+
.. versionchanged:: 1.0.0 The :meth:`.handle_error` event is now
invoked when an :class:`.Engine` fails during the initial
call to :meth:`.Engine.connect`, as well as when a