]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- Added new attributes :attr:`.ExecutionContext.exception` and
authorMike Bayer <mike_mp@zzzcomputing.com>
Fri, 4 Jul 2014 01:49:10 +0000 (21:49 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Fri, 4 Jul 2014 01:49:10 +0000 (21:49 -0400)
:attr:`.ExecutionContext.is_disconnect` which are meaningful within
the :meth:`.ConnectionEvents.dbapi_error` handler to see both the
original DBAPI error as well as whether or not it represents
a disconnect.

doc/build/changelog/changelog_09.rst
lib/sqlalchemy/engine/base.py
lib/sqlalchemy/engine/interfaces.py

index 01084eb86b965b988b092775cef74a19bcaacea6..7572aff10e95d8557162bcb6e44f5b5c9c46d7a8 100644 (file)
         of raising or returning a new exception object, which will replace
         the exception normally being thrown by SQLAlchemy.
 
+    .. change::
+        :tags: feature, engine
+        :versions: 1.0.0
+
+        Added new attributes :attr:`.ExecutionContext.exception` and
+        :attr:`.ExecutionContext.is_disconnect` which are meaningful within
+        the :meth:`.ConnectionEvents.dbapi_error` handler to see both the
+        original DBAPI error as well as whether or not it represents
+        a disconnect.
+
     .. change::
         :tags: bug, orm
         :tickets: 3108
index c885bcf69e716feee6e51df04ef8b8d4f0cd6918..67772f131efaf59c4052cfa6ef040bc2a0f0d820 100644 (file)
@@ -1070,10 +1070,16 @@ class Connection(Connectable):
 
         exc_info = sys.exc_info()
 
+        if context and context.exception is None:
+            context.exception = e
+
         if not self._is_disconnect:
-            self._is_disconnect = isinstance(e, self.dialect.dbapi.Error) and \
+            self._is_disconnect =  \
+                isinstance(e, self.dialect.dbapi.Error) and \
                 not self.closed and \
                 self.dialect.is_disconnect(e, self.__connection, cursor)
+            if context:
+                context.is_disconnect = self._is_disconnect
 
         if self._reentrant_error:
             util.raise_from_cause(
index 22801c28431c2ae7b21c3de87e4023eda6fcec91..230d00fc01c4a83c6948bc8f0639e1985b1f4465 100644 (file)
@@ -707,6 +707,41 @@ class ExecutionContext(object):
       and updates.
     """
 
+    exception = None
+    """A DBAPI-level exception that was caught when this ExecutionContext
+    attempted to execute a statement.
+
+    This attribute is meaningful only within the
+    :meth:`.ConnectionEvents.dbapi_error` event.
+
+    .. versionadded:: 0.9.7
+
+    .. seealso::
+
+        :attr:`.ExecutionContext.is_disconnect`
+
+        :meth:`.ConnectionEvents.dbapi_error`
+
+    """
+
+    is_disconnect = None
+    """Boolean flag set to True or False when a DBAPI-level exception
+    is caught when this ExecutionContext attempted to execute a statement.
+
+    This attribute is meaningful only within the
+    :meth:`.ConnectionEvents.dbapi_error` event.
+
+    .. versionadded:: 0.9.7
+
+    .. seealso::
+
+        :attr:`.ExecutionContext.exception`
+
+        :meth:`.ConnectionEvents.dbapi_error`
+
+    """
+
+
     def create_cursor(self):
         """Return a new cursor generated from this ExecutionContext's
         connection.