SQLAlchemy 2.0 Dokumentation
SQLAlchemy Core
- API für SQL-Anweisungen und Ausdrücke
- Schema Definition Language
- SQL Datentyp-Objekte
- Engine und Connection verwenden
- Grundlagen der Core API
- Events
- Runtime Inspection API
- Core Exceptions¶
AmbiguousForeignKeysErrorArgumentErrorAwaitRequiredBase20DeprecationWarningCircularDependencyErrorCompileErrorConstraintColumnNotFoundErrorDBAPIErrorDataErrorDatabaseErrorDisconnectionErrorDontWrapMixinDuplicateColumnErrorHasDescriptionCodeIdentifierErrorIllegalStateChangeErrorIntegrityErrorInterfaceErrorInternalErrorInvalidRequestErrorInvalidatePoolErrorLegacyAPIWarningMissingGreenletMovedIn20WarningMultipleResultsFoundNoForeignKeysErrorNoInspectionAvailableNoReferenceErrorNoReferencedColumnErrorNoReferencedTableErrorNoResultFoundNoSuchColumnErrorNoSuchModuleErrorNoSuchTableErrorNotSupportedErrorObjectNotExecutableErrorOperationalErrorPendingRollbackErrorProgrammingErrorResourceClosedErrorSADeprecationWarningSAPendingDeprecationWarningSATestSuiteWarningSAWarningSQLAlchemyErrorStatementErrorTimeoutErrorUnboundExecutionErrorUnreflectableTableErrorUnsupportedCompilationError
- Core Internals
Projektversionen
- Vorherige: Runtime Inspection API
- Nächste: Core Internals
- Nach oben: Startseite
- Auf dieser Seite
- Core Exceptions
AmbiguousForeignKeysErrorArgumentErrorAwaitRequiredBase20DeprecationWarningCircularDependencyErrorCompileErrorConstraintColumnNotFoundErrorDBAPIErrorDataErrorDatabaseErrorDisconnectionErrorDontWrapMixinDuplicateColumnErrorHasDescriptionCodeIdentifierErrorIllegalStateChangeErrorIntegrityErrorInterfaceErrorInternalErrorInvalidRequestErrorInvalidatePoolErrorLegacyAPIWarningMissingGreenletMovedIn20WarningMultipleResultsFoundNoForeignKeysErrorNoInspectionAvailableNoReferenceErrorNoReferencedColumnErrorNoReferencedTableErrorNoResultFoundNoSuchColumnErrorNoSuchModuleErrorNoSuchTableErrorNotSupportedErrorObjectNotExecutableErrorOperationalErrorPendingRollbackErrorProgrammingErrorResourceClosedErrorSADeprecationWarningSAPendingDeprecationWarningSATestSuiteWarningSAWarningSQLAlchemyErrorStatementErrorTimeoutErrorUnboundExecutionErrorUnreflectableTableErrorUnsupportedCompilationError
Core Exceptions¶
Exceptions used with SQLAlchemy.
Die Basis-Exception-Klasse ist SQLAlchemyError. Exceptions, die als Ergebnis von DBAPI-Exceptions ausgelöst werden, sind alle Unterklassen von DBAPIError.
- exception sqlalchemy.exc.AmbiguousForeignKeysError¶
Raised when more than one foreign key matching can be located between two selectables during a join.
Klassensignatur
class
sqlalchemy.exc.AmbiguousForeignKeysError(sqlalchemy.exc.ArgumentError)
- exception sqlalchemy.exc.ArgumentError¶
Raised when an invalid or conflicting function argument is supplied.
This error generally corresponds to construction time state errors.
Klassensignatur
class
sqlalchemy.exc.ArgumentError(sqlalchemy.exc.SQLAlchemyError)
- exception sqlalchemy.exc.AwaitRequired¶
Error raised by the async greenlet spawn if no async operation was awaited when it required one.
Klassensignatur
class
sqlalchemy.exc.AwaitRequired(sqlalchemy.exc.InvalidRequestError)
- exception sqlalchemy.exc.Base20DeprecationWarning¶
Issued for usage of APIs specifically deprecated or legacy in SQLAlchemy 2.0.
Klassensignatur
class
sqlalchemy.exc.Base20DeprecationWarning(sqlalchemy.exc.SADeprecationWarning)-
attribute
sqlalchemy.exc.Base20DeprecationWarning.deprecated_since: str | None = '1.4'¶ Indicates the version that started raising this deprecation warning
-
attribute
- exception sqlalchemy.exc.CircularDependencyError¶
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_updateflag described at Rows that point to themselves / Mutually Dependent Rows can resolve this cycle.In a
MetaData.sorted_tablesoperation, twoForeignKeyorForeignKeyConstraintobjects mutually refer to each other. Apply theuse_alter=Trueflag to one or both, see Creating/Dropping Foreign Key Constraints via ALTER.
Klassensignatur
class
sqlalchemy.exc.CircularDependencyError(sqlalchemy.exc.SQLAlchemyError)-
method
sqlalchemy.exc.CircularDependencyError.__init__(message: str, cycles: Any, edges: Any, msg: str | None = None, code: str | None = None)¶
- exception sqlalchemy.exc.CompileError¶
Raised when an error occurs during SQL compilation
Klassensignatur
class
sqlalchemy.exc.CompileError(sqlalchemy.exc.SQLAlchemyError)
- exception sqlalchemy.exc.ConstraintColumnNotFoundError¶
raised when a constraint refers to a string column name that is not present in the table being constrained.
Neu in Version 2.0.
Klassensignatur
class
sqlalchemy.exc.ConstraintColumnNotFoundError(sqlalchemy.exc.ArgumentError)
- exception sqlalchemy.exc.DBAPIError¶
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
DBAPIErrorwhen possible. DB-API’sErrortype maps toDBAPIErrorin 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.DBAPIErrorfeaturesStatementError.statementandStatementError.paramsattributes 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.origattribute. Its type and properties are DB-API implementation specific.Klassensignatur
class
sqlalchemy.exc.DBAPIError(sqlalchemy.exc.StatementError)-
method
sqlalchemy.exc.DBAPIError.__init__(statement: str | None, params: _AnyExecuteParams | None, orig: BaseException, hide_parameters: bool = False, connection_invalidated: bool = False, code: str | None = None, ismulti: bool | None = None)¶
-
method
- exception sqlalchemy.exc.DataError¶
Wraps a DB-API DataError.
Klassensignatur
class
sqlalchemy.exc.DataError(sqlalchemy.exc.DatabaseError)
- exception sqlalchemy.exc.DatabaseError¶
Wraps a DB-API DatabaseError.
Klassensignatur
class
sqlalchemy.exc.DatabaseError(sqlalchemy.exc.DBAPIError)
- exception sqlalchemy.exc.DisconnectionError¶
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 raisesInvalidRequestErrorregarding the connection attempt.Klassensignatur
class
sqlalchemy.exc.DisconnectionError(sqlalchemy.exc.SQLAlchemyError)
| Objektname | Beschreibung |
|---|---|
A mixin class which, when applied to a user-defined Exception class, will not be wrapped inside of |
|
helper which adds ‘code’ as an attribute and ‘_code_str’ as a method |
- class sqlalchemy.exc.DontWrapMixin¶
A mixin class which, when applied to a user-defined Exception class, will not be wrapped inside of
StatementErrorif the error is emitted within the process of executing a statement.Z. B.
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.DuplicateColumnError¶
a Column is being added to a Table that would replace another Column, without appropriate parameters to allow this in place.
Neu ab Version 2.0.0b4.
Klassensignatur
class
sqlalchemy.exc.DuplicateColumnError(sqlalchemy.exc.ArgumentError)
- class sqlalchemy.exc.HasDescriptionCode¶
helper which adds ‘code’ as an attribute and ‘_code_str’ as a method
- exception sqlalchemy.exc.IdentifierError¶
Raised when a schema name is beyond the max character limit
Klassensignatur
class
sqlalchemy.exc.IdentifierError(sqlalchemy.exc.SQLAlchemyError)
- exception sqlalchemy.exc.IllegalStateChangeError¶
An object that tracks state encountered an illegal state change of some kind.
Neu in Version 2.0.
Klassensignatur
class
sqlalchemy.exc.IllegalStateChangeError(sqlalchemy.exc.InvalidRequestError)
- exception sqlalchemy.exc.IntegrityError¶
Wraps a DB-API IntegrityError.
Klassensignatur
class
sqlalchemy.exc.IntegrityError(sqlalchemy.exc.DatabaseError)
- exception sqlalchemy.exc.InterfaceError¶
Wraps a DB-API InterfaceError.
Klassensignatur
class
sqlalchemy.exc.InterfaceError(sqlalchemy.exc.DBAPIError)
- exception sqlalchemy.exc.InternalError¶
Wraps a DB-API InternalError.
Klassensignatur
class
sqlalchemy.exc.InternalError(sqlalchemy.exc.DatabaseError)
- exception sqlalchemy.exc.InvalidRequestError¶
SQLAlchemy was asked to do something it can’t do.
This error generally corresponds to runtime state errors.
Klassensignatur
class
sqlalchemy.exc.InvalidRequestError(sqlalchemy.exc.SQLAlchemyError)
- exception sqlalchemy.exc.InvalidatePoolError¶
Raised when the connection pool should invalidate all stale connections.
A subclass of
DisconnectionErrorthat 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.Neu seit Version 1.2.
Klassensignatur
class
sqlalchemy.exc.InvalidatePoolError(sqlalchemy.exc.DisconnectionError)
- exception sqlalchemy.exc.LegacyAPIWarning¶
indicates an API that is in ‘legacy’ status, a long term deprecation.
Klassensignatur
class
sqlalchemy.exc.LegacyAPIWarning(sqlalchemy.exc.Base20DeprecationWarning)
- exception sqlalchemy.exc.MissingGreenlet¶
Error raised by the async greenlet await_ if called while not inside the greenlet spawn context.
Klassensignatur
class
sqlalchemy.exc.MissingGreenlet(sqlalchemy.exc.InvalidRequestError)
- exception sqlalchemy.exc.MovedIn20Warning¶
Subtype of RemovedIn20Warning to indicate an API that moved only.
Klassensignatur
class
sqlalchemy.exc.MovedIn20Warning(sqlalchemy.exc.Base20DeprecationWarning)
- exception sqlalchemy.exc.MultipleResultsFound¶
A single database result was required but more than one were found.
Changed in version 1.4: This exception is now part of the
sqlalchemy.excmodule in Core, moved from the ORM. The symbol remains importable fromsqlalchemy.orm.exc.Klassensignatur
class
sqlalchemy.exc.MultipleResultsFound(sqlalchemy.exc.InvalidRequestError)
- exception sqlalchemy.exc.NoForeignKeysError¶
Raised when no foreign keys can be located between two selectables during a join.
Klassensignatur
class
sqlalchemy.exc.NoForeignKeysError(sqlalchemy.exc.ArgumentError)
- exception sqlalchemy.exc.NoInspectionAvailable¶
A subject passed to
sqlalchemy.inspection.inspect()produced no context for inspection.Klassensignatur
class
sqlalchemy.exc.NoInspectionAvailable(sqlalchemy.exc.InvalidRequestError)
- exception sqlalchemy.exc.NoReferenceError¶
Raised by
ForeignKeyto indicate a reference cannot be resolved.Klassensignatur
class
sqlalchemy.exc.NoReferenceError(sqlalchemy.exc.InvalidRequestError)
- exception sqlalchemy.exc.NoReferencedColumnError¶
Raised by
ForeignKeywhen the referredColumncannot be located.Klassensignatur
class
sqlalchemy.exc.NoReferencedColumnError(sqlalchemy.exc.NoReferenceError)-
method
sqlalchemy.exc.NoReferencedColumnError.__init__(message: str, tname: str, cname: str)¶
-
method
- exception sqlalchemy.exc.NoReferencedTableError¶
Raised by
ForeignKeywhen the referredTablecannot be located.Klassensignatur
class
sqlalchemy.exc.NoReferencedTableError(sqlalchemy.exc.NoReferenceError)-
method
sqlalchemy.exc.NoReferencedTableError.__init__(message: str, tname: str)¶
-
method
- exception sqlalchemy.exc.NoResultFound¶
A database result was required but none was found.
Changed in version 1.4: This exception is now part of the
sqlalchemy.excmodule in Core, moved from the ORM. The symbol remains importable fromsqlalchemy.orm.exc.Klassensignatur
class
sqlalchemy.exc.NoResultFound(sqlalchemy.exc.InvalidRequestError)
- exception sqlalchemy.exc.NoSuchColumnError¶
A nonexistent column is requested from a
Row.Klassensignatur
class
sqlalchemy.exc.NoSuchColumnError(sqlalchemy.exc.InvalidRequestError,builtins.KeyError)
- exception sqlalchemy.exc.NoSuchModuleError¶
Raised when a dynamically-loaded module (usually a database dialect) of a particular name cannot be located.
Klassensignatur
class
sqlalchemy.exc.NoSuchModuleError(sqlalchemy.exc.ArgumentError)
- exception sqlalchemy.exc.NoSuchTableError¶
Table does not exist or is not visible to a connection.
Klassensignatur
class
sqlalchemy.exc.NoSuchTableError(sqlalchemy.exc.InvalidRequestError)
- exception sqlalchemy.exc.NotSupportedError¶
Umschließt einen DB-API NotSupportedError.
Klassensignatur
class
sqlalchemy.exc.NotSupportedError(sqlalchemy.exc.DatabaseError)
- exception sqlalchemy.exc.ObjectNotExecutableError¶
Ausgelöst, wenn ein Objekt an .execute() übergeben wird, das nicht als SQL ausgeführt werden kann.
Klassensignatur
class
sqlalchemy.exc.ObjectNotExecutableError(sqlalchemy.exc.ArgumentError)-
method
sqlalchemy.exc.ObjectNotExecutableError.__init__(target: Any)¶
-
method
- exception sqlalchemy.exc.OperationalError¶
Umschließt einen DB-API OperationalError.
Klassensignatur
class
sqlalchemy.exc.OperationalError(sqlalchemy.exc.DatabaseError)
- exception sqlalchemy.exc.PendingRollbackError¶
Eine Transaktion ist fehlgeschlagen und muss vor der Fortsetzung zurückgerollt werden.
Neu in Version 1.4.
Klassensignatur
class
sqlalchemy.exc.PendingRollbackError(sqlalchemy.exc.InvalidRequestError)
- exception sqlalchemy.exc.ProgrammingError¶
Umschließt einen DB-API ProgrammingError.
Klassensignatur
class
sqlalchemy.exc.ProgrammingError(sqlalchemy.exc.DatabaseError)
- exception sqlalchemy.exc.ResourceClosedError¶
Eine Operation wurde von einer Verbindung, einem Cursor oder einem anderen Objekt angefordert, das sich in einem geschlossenen Zustand befindet.
Klassensignatur
class
sqlalchemy.exc.ResourceClosedError(sqlalchemy.exc.InvalidRequestError)
- exception sqlalchemy.exc.SADeprecationWarning¶
Ausgegeben für die Verwendung veralteter APIs.
Klassensignatur
class
sqlalchemy.exc.SADeprecationWarning(sqlalchemy.exc.HasDescriptionCode,builtins.DeprecationWarning)-
attribute
sqlalchemy.exc.SADeprecationWarning.deprecated_since: str | None = None¶ Indicates the version that started raising this deprecation warning
-
attribute
- exception sqlalchemy.exc.SAPendingDeprecationWarning¶
Eine ähnliche Warnung wie
SADeprecationWarning, diese Warnung wird in modernen Versionen von SQLAlchemy nicht verwendet.Klassensignatur
class
sqlalchemy.exc.SAPendingDeprecationWarning(builtins.PendingDeprecationWarning)-
attribute
sqlalchemy.exc.SAPendingDeprecationWarning.deprecated_since: str | None = None¶ Indicates the version that started raising this deprecation warning
-
attribute
- exception sqlalchemy.exc.SATestSuiteWarning¶
Warnung für eine Bedingung, die während Tests erkannt wurde und nicht-fatal ist
Derzeit außerhalb von SAWarning, damit wir mit Tools wie Alembic umgehen können, die Warnungen falsch verarbeiten.
Klassensignatur
class
sqlalchemy.exc.SATestSuiteWarning(builtins.Warning)
- exception sqlalchemy.exc.SAWarning¶
Zur Laufzeit ausgegeben.
Klassensignatur
class
sqlalchemy.exc.SAWarning(sqlalchemy.exc.HasDescriptionCode,builtins.RuntimeWarning)
- exception sqlalchemy.exc.SQLAlchemyError¶
Generische Fehlerklasse.
Klassensignatur
class
sqlalchemy.exc.SQLAlchemyError(sqlalchemy.exc.HasDescriptionCode,builtins.Exception)
- exception sqlalchemy.exc.StatementError¶
Ein Fehler ist während der Ausführung einer SQL-Anweisung aufgetreten.
StatementErrorumschließt die Ausnahme, die während der Ausführung ausgelöst wurde, und verfügt über die Attributestatementundparams, die Kontext zu den Details der Anweisung liefern, die ein Problem hatte.Das umschlossene Ausnahmeobjekt ist im Attribut
origverfügbar.Klassensignatur
class
sqlalchemy.exc.StatementError(sqlalchemy.exc.SQLAlchemyError)-
method
sqlalchemy.exc.StatementError.__init__(message: str, statement: str | None, params: _AnyExecuteParams | None, orig: BaseException | None, hide_parameters: bool = False, code: str | None = None, ismulti: bool | None = None)¶
-
attribute
sqlalchemy.exc.StatementError.ismulti: bool | None = None¶ multi-Parameter, der an repr_params() übergeben wird. None ist aussagekräftig.
-
attribute
sqlalchemy.exc.StatementError.orig: BaseException | None = None¶ Die ursprüngliche Ausnahme, die ausgelöst wurde.
-
attribute
sqlalchemy.exc.StatementError.params: _AnyExecuteParams | None = None¶ Die Parameterliste, die verwendet wurde, als dieser Fehler auftrat.
-
attribute
sqlalchemy.exc.StatementError.statement: str | None = None¶ Die Zeichenkette der SQL-Anweisung, die beim Auftreten dieser Ausnahme aufgerufen wurde.
-
method
- exception sqlalchemy.exc.TimeoutError¶
Ausgelöst, wenn ein Verbindungspool beim Abrufen einer Verbindung eine Zeitüberschreitung aufweist.
Klassensignatur
class
sqlalchemy.exc.TimeoutError(sqlalchemy.exc.SQLAlchemyError)
- exception sqlalchemy.exc.UnboundExecutionError¶
SQL wurde versucht, ohne eine Datenbankverbindung zur Ausführung.
Klassensignatur
class
sqlalchemy.exc.UnboundExecutionError(sqlalchemy.exc.InvalidRequestError)
- exception sqlalchemy.exc.UnreflectableTableError¶
Die Tabelle existiert, kann aber aus irgendeinem Grund nicht reflektiert werden.
Neu seit Version 1.2.
Klassensignatur
class
sqlalchemy.exc.UnreflectableTableError(sqlalchemy.exc.InvalidRequestError)
- exception sqlalchemy.exc.UnsupportedCompilationError¶
Ausgelöst, wenn eine Operation vom angegebenen Compiler nicht unterstützt wird.
Siehe auch
Wie rendere ich SQL-Ausdrücke als Strings, möglicherweise mit eingebetteten gebundenen Parametern?
Compiler StrSQLCompiler kann Element vom Typ <element type> nicht rendern
Klassensignatur
class
sqlalchemy.exc.UnsupportedCompilationError(sqlalchemy.exc.CompileError)-
method
sqlalchemy.exc.UnsupportedCompilationError.__init__(compiler: Compiled | TypeCompiler, element_type: Type[ClauseElement], message: str | None = None)¶
-
method
Die Designs von flambé! dem Drachen und Der Alchemist wurden von Rotem Yaari erstellt und großzügig gespendet.
Erstellt mit Sphinx 7.2.6. Dokumentation zuletzt generiert: Di 11 Mär 2025 14:40:17 EDT