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
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(
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.