class documentation

class ExceptionContext(object):

Known subclasses: sqlalchemy.engine.base.ExceptionContextImpl

View In Hierarchy

Encapsulate information about an error condition in progress.

This object exists solely to be passed to the _events.ConnectionEvents.handle_error event, supporting an interface that can be extended without backwards-incompatibility.

New in version 0.9.7.
Class Variable chained​_exception The exception that was returned by the previous handler in the exception chain, if any.
Class Variable connection The _engine.Connection in use during the exception.
Class Variable cursor The DBAPI cursor object.
Class Variable engine The _engine.Engine in use during the exception.
Class Variable execution​_context The .ExecutionContext corresponding to the execution operation in progress.
Class Variable invalidate​_pool​_on​_disconnect Represent whether all connections in the pool should be invalidated when a "disconnect" condition is in effect.
Class Variable is​_disconnect Represent whether the exception as occurred represents a "disconnect" condition.
Class Variable original​_exception The exception object which was caught.
Class Variable parameters Parameter collection that was emitted directly to the DBAPI.
Class Variable sqlalchemy​_exception The sqlalchemy.exc.StatementError which wraps the original, and will be raised if exception handling is not circumvented by the event.
Class Variable statement String SQL statement that was emitted directly to the DBAPI.
chained_exception =

The exception that was returned by the previous handler in the exception chain, if any.

If present, this exception will be the one ultimately raised by SQLAlchemy unless a subsequent handler replaces it.

May be None.

connection =

The _engine.Connection in use during the exception.

This member is present, except in the case of a failure when first connecting.

See Also

.ExceptionContext.engine

cursor =

The DBAPI cursor object.

May be None.

engine =

The _engine.Engine in use during the exception.

This member should always be present, even in the case of a failure when first connecting.

New in version 1.0.0.
execution_context =

The .ExecutionContext corresponding to the execution operation in progress.

This is present for statement execution operations, but not for operations such as transaction begin/end. It also is not present when the exception was raised before the .ExecutionContext could be constructed.

Note that the .ExceptionContext.statement and .ExceptionContext.parameters members may represent a different value than that of the .ExecutionContext, potentially in the case where a _events.ConnectionEvents.before_cursor_execute event or similar modified the statement/parameters to be sent.

May be None.

invalidate_pool_on_disconnect: bool =

Represent whether all connections in the pool should be invalidated when a "disconnect" condition is in effect.

Setting this flag to False within the scope of the _events.ConnectionEvents.handle_error event will have the effect such that the full collection of connections in the pool will not be invalidated during a disconnect; only the current connection that is the subject of the error will actually be invalidated.

The purpose of this flag is for custom disconnect-handling schemes where the invalidation of other connections in the pool is to be performed based on other conditions, or even on a per-connection basis.

New in version 1.0.3.
is_disconnect =

Represent whether the exception as occurred represents a "disconnect" condition.

This flag will always be True or False within the scope of the _events.ConnectionEvents.handle_error handler.

SQLAlchemy will defer to this flag in order to determine whether or not the connection should be invalidated subsequently. That is, by assigning to this flag, a "disconnect" event which then results in a connection and pool invalidation can be invoked or prevented by changing this flag.

Note

The pool "pre_ping" handler enabled using the :paramref:`_sa.create_engine.pool_pre_ping` parameter does not consult this event before deciding if the "ping" returned false, as opposed to receiving an unhandled error. For this use case, the :ref:`legacy recipe based on engine_connect() may be used <pool_disconnects_pessimistic_custom>`. A future API allow more comprehensive customization of the "disconnect" detection mechanism across all functions.

original_exception =

The exception object which was caught.

This member is always present.

parameters =

Parameter collection that was emitted directly to the DBAPI.

May be None.

sqlalchemy_exception =

The sqlalchemy.exc.StatementError which wraps the original, and will be raised if exception handling is not circumvented by the event.

May be None, as not all exception types are wrapped by SQLAlchemy. For DBAPI-level exceptions that subclass the dbapi's Error class, this field will always be present.

statement =

String SQL statement that was emitted directly to the DBAPI.

May be None.