SQLAlchemy 1.3 Documentation
SQLAlchemy Core
- SQL Expression Language Tutorial
- SQL Statements and Expressions API
- Schema Definition Language
- Column and Data Types
- Engine and Connection Use
- Core API Basics
- Events
- Runtime Inspection API
- Deprecated Event Interfaces
- Core Exceptions¶
AmbiguousForeignKeysError
ArgumentError
CircularDependencyError
CompileError
DBAPIError
DataError
DatabaseError
DisconnectionError
DontWrapMixin
IdentifierError
IntegrityError
InterfaceError
InternalError
InvalidRequestError
InvalidatePoolError
NoForeignKeysError
NoInspectionAvailable
NoReferenceError
NoReferencedColumnError
NoReferencedTableError
NoSuchColumnError
NoSuchModuleError
NoSuchTableError
NotSupportedError
ObjectNotExecutableError
OperationalError
ProgrammingError
ResourceClosedError
SADeprecationWarning
SAPendingDeprecationWarning
SAWarning
SQLAlchemyError
StatementError
TimeoutError
UnboundExecutionError
UnreflectableTableError
UnsupportedCompilationError
- Core Internals
Project Versions
- Previous: Deprecated Event Interfaces
- Next: Core Internals
- Up: Home
- On this page:
- Core Exceptions
AmbiguousForeignKeysError
ArgumentError
CircularDependencyError
CompileError
DBAPIError
DataError
DatabaseError
DisconnectionError
DontWrapMixin
IdentifierError
IntegrityError
InterfaceError
InternalError
InvalidRequestError
InvalidatePoolError
NoForeignKeysError
NoInspectionAvailable
NoReferenceError
NoReferencedColumnError
NoReferencedTableError
NoSuchColumnError
NoSuchModuleError
NoSuchTableError
NotSupportedError
ObjectNotExecutableError
OperationalError
ProgrammingError
ResourceClosedError
SADeprecationWarning
SAPendingDeprecationWarning
SAWarning
SQLAlchemyError
StatementError
TimeoutError
UnboundExecutionError
UnreflectableTableError
UnsupportedCompilationError
Core Exceptions¶
Exceptions used with SQLAlchemy.
The base exception class is SQLAlchemyError
. Exceptions which are
raised as a result of DBAPI exceptions are all subclasses of
DBAPIError
.
- exception sqlalchemy.exc.AmbiguousForeignKeysError(*arg, **kw)¶
Raised when more than one foreign key matching can be located between two selectables during a join.
Class signature
class
sqlalchemy.exc.AmbiguousForeignKeysError
(sqlalchemy.exc.ArgumentError
)
- exception sqlalchemy.exc.ArgumentError(*arg, **kw)¶
Raised when an invalid or conflicting function argument is supplied.
This error generally corresponds to construction time state errors.
Class signature
class
sqlalchemy.exc.ArgumentError
(sqlalchemy.exc.SQLAlchemyError
)
- exception sqlalchemy.exc.CircularDependencyError(message, cycles, edges, msg=None, code=None)¶
Raised by topological sorts when a circular dependency is detected.
There are two scenarios where this error occurs:
In a Session flush operation, if two objects are mutually dependent on each other, they can not be inserted or deleted via INSERT or DELETE statements alone; an UPDATE will be needed to post-associate or pre-deassociate one of the foreign key constrained values. The
post_update
flag described at Rows that point to themselves / Mutually Dependent Rows can resolve this cycle.In a
MetaData.sorted_tables
operation, twoForeignKey
orForeignKeyConstraint
objects mutually refer to each other. Apply theuse_alter=True
flag to one or both, see Creating/Dropping Foreign Key Constraints via ALTER.
Class signature
class
sqlalchemy.exc.CircularDependencyError
(sqlalchemy.exc.SQLAlchemyError
)
- exception sqlalchemy.exc.CompileError(*arg, **kw)¶
Raised when an error occurs during SQL compilation
Class signature
class
sqlalchemy.exc.CompileError
(sqlalchemy.exc.SQLAlchemyError
)
- exception sqlalchemy.exc.DBAPIError(statement, params, orig, hide_parameters=False, connection_invalidated=False, code=None, ismulti=None)¶
Raised when the execution of a database operation fails.
Wraps exceptions raised by the DB-API underlying the database operation. Driver-specific implementations of the standard DB-API exception types are wrapped by matching sub-types of SQLAlchemy’s
DBAPIError
when possible. DB-API’sError
type maps toDBAPIError
in SQLAlchemy, otherwise the names are identical. Note that there is no guarantee that different DB-API implementations will raise the same exception type for any given error condition.DBAPIError
featuresStatementError.statement
andStatementError.params
attributes which supply context regarding the specifics of the statement which had an issue, for the typical case when the error was raised within the context of emitting a SQL statement.The wrapped exception object is available in the
StatementError.orig
attribute. Its type and properties are DB-API implementation specific.Class signature
class
sqlalchemy.exc.DBAPIError
(sqlalchemy.exc.StatementError
)
- exception sqlalchemy.exc.DataError(statement, params, orig, hide_parameters=False, connection_invalidated=False, code=None, ismulti=None)¶
Wraps a DB-API DataError.
Class signature
class
sqlalchemy.exc.DataError
(sqlalchemy.exc.DatabaseError
)
- exception sqlalchemy.exc.DatabaseError(statement, params, orig, hide_parameters=False, connection_invalidated=False, code=None, ismulti=None)¶
Wraps a DB-API DatabaseError.
Class signature
class
sqlalchemy.exc.DatabaseError
(sqlalchemy.exc.DBAPIError
)
- exception sqlalchemy.exc.DisconnectionError(*arg, **kw)¶
A disconnect is detected on a raw DB-API connection.
This error is raised and consumed internally by a connection pool. It can be raised by the
PoolEvents.checkout()
event so that the host pool forces a retry; the exception will be caught three times in a row before the pool gives up and raisesInvalidRequestError
regarding the connection attempt.Class signature
class
sqlalchemy.exc.DisconnectionError
(sqlalchemy.exc.SQLAlchemyError
)
Object Name | Description |
---|---|
A mixin class which, when applied to a user-defined Exception class,
will not be wrapped inside of |
- class sqlalchemy.exc.DontWrapMixin¶
A mixin class which, when applied to a user-defined Exception class, will not be wrapped inside of
StatementError
if the error is emitted within the process of executing a statement.E.g.:
from sqlalchemy.exc import DontWrapMixin class MyCustomException(Exception, DontWrapMixin): pass class MySpecialType(TypeDecorator): impl = String def process_bind_param(self, value, dialect): if value == 'invalid': raise MyCustomException("invalid!")
- exception sqlalchemy.exc.IdentifierError(*arg, **kw)¶
Raised when a schema name is beyond the max character limit
Class signature
class
sqlalchemy.exc.IdentifierError
(sqlalchemy.exc.SQLAlchemyError
)
- exception sqlalchemy.exc.IntegrityError(statement, params, orig, hide_parameters=False, connection_invalidated=False, code=None, ismulti=None)¶
Wraps a DB-API IntegrityError.
Class signature
class
sqlalchemy.exc.IntegrityError
(sqlalchemy.exc.DatabaseError
)
- exception sqlalchemy.exc.InterfaceError(statement, params, orig, hide_parameters=False, connection_invalidated=False, code=None, ismulti=None)¶
Wraps a DB-API InterfaceError.
Class signature
class
sqlalchemy.exc.InterfaceError
(sqlalchemy.exc.DBAPIError
)
- exception sqlalchemy.exc.InternalError(statement, params, orig, hide_parameters=False, connection_invalidated=False, code=None, ismulti=None)¶
Wraps a DB-API InternalError.
Class signature
class
sqlalchemy.exc.InternalError
(sqlalchemy.exc.DatabaseError
)
- exception sqlalchemy.exc.InvalidRequestError(*arg, **kw)¶
SQLAlchemy was asked to do something it can’t do.
This error generally corresponds to runtime state errors.
Class signature
class
sqlalchemy.exc.InvalidRequestError
(sqlalchemy.exc.SQLAlchemyError
)
- exception sqlalchemy.exc.InvalidatePoolError(*arg, **kw)¶
Raised when the connection pool should invalidate all stale connections.
A subclass of
DisconnectionError
that indicates that the disconnect situation encountered on the connection probably means the entire pool should be invalidated, as the database has been restarted.This exception will be handled otherwise the same way as
DisconnectionError
, allowing three attempts to reconnect before giving up.New in version 1.2.
Class signature
class
sqlalchemy.exc.InvalidatePoolError
(sqlalchemy.exc.DisconnectionError
)
- exception sqlalchemy.exc.NoForeignKeysError(*arg, **kw)¶
Raised when no foreign keys can be located between two selectables during a join.
Class signature
class
sqlalchemy.exc.NoForeignKeysError
(sqlalchemy.exc.ArgumentError
)
- exception sqlalchemy.exc.NoInspectionAvailable(*arg, **kw)¶
A subject passed to
sqlalchemy.inspection.inspect()
produced no context for inspection.Class signature
class
sqlalchemy.exc.NoInspectionAvailable
(sqlalchemy.exc.InvalidRequestError
)
- exception sqlalchemy.exc.NoReferenceError(*arg, **kw)¶
Raised by
ForeignKey
to indicate a reference cannot be resolved.Class signature
class
sqlalchemy.exc.NoReferenceError
(sqlalchemy.exc.InvalidRequestError
)
- exception sqlalchemy.exc.NoReferencedColumnError(message, tname, cname)¶
Raised by
ForeignKey
when the referredColumn
cannot be located.Class signature
class
sqlalchemy.exc.NoReferencedColumnError
(sqlalchemy.exc.NoReferenceError
)
- exception sqlalchemy.exc.NoReferencedTableError(message, tname)¶
Raised by
ForeignKey
when the referredTable
cannot be located.Class signature
class
sqlalchemy.exc.NoReferencedTableError
(sqlalchemy.exc.NoReferenceError
)
- exception sqlalchemy.exc.NoSuchColumnError¶
A nonexistent column is requested from a
RowProxy
.Class signature
class
sqlalchemy.exc.NoSuchColumnError
(builtins.KeyError
,sqlalchemy.exc.InvalidRequestError
)
- exception sqlalchemy.exc.NoSuchModuleError(*arg, **kw)¶
Raised when a dynamically-loaded module (usually a database dialect) of a particular name cannot be located.
Class signature
class
sqlalchemy.exc.NoSuchModuleError
(sqlalchemy.exc.ArgumentError
)
- exception sqlalchemy.exc.NoSuchTableError(*arg, **kw)¶
Table does not exist or is not visible to a connection.
Class signature
class
sqlalchemy.exc.NoSuchTableError
(sqlalchemy.exc.InvalidRequestError
)
- exception sqlalchemy.exc.NotSupportedError(statement, params, orig, hide_parameters=False, connection_invalidated=False, code=None, ismulti=None)¶
Wraps a DB-API NotSupportedError.
Class signature
class
sqlalchemy.exc.NotSupportedError
(sqlalchemy.exc.DatabaseError
)
- exception sqlalchemy.exc.ObjectNotExecutableError(target)¶
Raised when an object is passed to .execute() that can’t be executed as SQL.
New in version 1.1.
Class signature
class
sqlalchemy.exc.ObjectNotExecutableError
(sqlalchemy.exc.ArgumentError
)
- exception sqlalchemy.exc.OperationalError(statement, params, orig, hide_parameters=False, connection_invalidated=False, code=None, ismulti=None)¶
Wraps a DB-API OperationalError.
Class signature
class
sqlalchemy.exc.OperationalError
(sqlalchemy.exc.DatabaseError
)
- exception sqlalchemy.exc.ProgrammingError(statement, params, orig, hide_parameters=False, connection_invalidated=False, code=None, ismulti=None)¶
Wraps a DB-API ProgrammingError.
Class signature
class
sqlalchemy.exc.ProgrammingError
(sqlalchemy.exc.DatabaseError
)
- exception sqlalchemy.exc.ResourceClosedError(*arg, **kw)¶
An operation was requested from a connection, cursor, or other object that’s in a closed state.
Class signature
class
sqlalchemy.exc.ResourceClosedError
(sqlalchemy.exc.InvalidRequestError
)
- exception sqlalchemy.exc.SADeprecationWarning¶
Issued once per usage of a deprecated API.
Class signature
class
sqlalchemy.exc.SADeprecationWarning
(builtins.DeprecationWarning
)
- exception sqlalchemy.exc.SAPendingDeprecationWarning¶
Issued once per usage of a deprecated API.
Class signature
class
sqlalchemy.exc.SAPendingDeprecationWarning
(builtins.PendingDeprecationWarning
)
- exception sqlalchemy.exc.SAWarning¶
Issued at runtime.
Class signature
class
sqlalchemy.exc.SAWarning
(builtins.RuntimeWarning
)
- exception sqlalchemy.exc.SQLAlchemyError(*arg, **kw)¶
Generic error class.
Class signature
class
sqlalchemy.exc.SQLAlchemyError
(builtins.Exception
)
- exception sqlalchemy.exc.StatementError(message, statement, params, orig, hide_parameters=False, code=None, ismulti=None)¶
An error occurred during execution of a SQL statement.
StatementError
wraps the exception raised during execution, and featuresstatement
andparams
attributes which supply context regarding the specifics of the statement which had an issue.The wrapped exception object is available in the
orig
attribute.Class signature
class
sqlalchemy.exc.StatementError
(sqlalchemy.exc.SQLAlchemyError
)-
attribute
sqlalchemy.exc.StatementError.
orig = None¶ The DBAPI exception object.
-
attribute
sqlalchemy.exc.StatementError.
params = None¶ The parameter list being used when this exception occurred.
-
attribute
sqlalchemy.exc.StatementError.
statement = None¶ The string SQL statement being invoked when this exception occurred.
-
attribute
- exception sqlalchemy.exc.TimeoutError(*arg, **kw)¶
Raised when a connection pool times out on getting a connection.
Class signature
class
sqlalchemy.exc.TimeoutError
(sqlalchemy.exc.SQLAlchemyError
)
- exception sqlalchemy.exc.UnboundExecutionError(*arg, **kw)¶
SQL was attempted without a database connection to execute it on.
Class signature
class
sqlalchemy.exc.UnboundExecutionError
(sqlalchemy.exc.InvalidRequestError
)
- exception sqlalchemy.exc.UnreflectableTableError(*arg, **kw)¶
Table exists but can’t be reflected for some reason.
New in version 1.2.
Class signature
class
sqlalchemy.exc.UnreflectableTableError
(sqlalchemy.exc.InvalidRequestError
)
- exception sqlalchemy.exc.UnsupportedCompilationError(compiler, element_type, message=None)¶
Raised when an operation is not supported by the given compiler.
See also
How do I render SQL expressions as strings, possibly with bound parameters inlined?
Compiler StrSQLCompiler can’t render element of type <element type>
Class signature
class
sqlalchemy.exc.UnsupportedCompilationError
(sqlalchemy.exc.CompileError
)
flambé! the dragon and The Alchemist image designs created and generously donated by Rotem Yaari.
Created using Sphinx 7.2.6. Documentation last generated: Sat 06 Jan 2024 12:15:53 PM