diff options
author | Federico Caselli <cfederico87@gmail.com> | 2021-09-27 15:40:47 -0400 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2021-10-01 17:22:57 -0400 |
commit | 2f4abe24d2754e8d35f43e684e5fa303c1c8d15b (patch) | |
tree | c21cdae700aa9d936877ab59372c93de463e90e2 /lib/sqlalchemy/exc.py | |
parent | 7f87cad26c1726565a200f85b7855bf8192e8df5 (diff) | |
download | sqlalchemy-2f4abe24d2754e8d35f43e684e5fa303c1c8d15b.tar.gz |
Ensure all SQLAlchemy exception can be properly pickled
Implemented proper ``__reduce__()`` methods for all SQLAlchemy exception
objects to ensure they all support clean round trips when pickling, as
exception objects are often serialized for the purposes of various
debugging tools.
Fixes #7077
Closes: #7078
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/7078
Pull-request-sha: 8ba69f26532f0f60f679289702c9477e25149bf8
Change-Id: Id62f8d351cd9180c441ffa9201efcf5f1876bf83
Diffstat (limited to 'lib/sqlalchemy/exc.py')
-rw-r--r-- | lib/sqlalchemy/exc.py | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/lib/sqlalchemy/exc.py b/lib/sqlalchemy/exc.py index a24cf7ba4..afda1b779 100644 --- a/lib/sqlalchemy/exc.py +++ b/lib/sqlalchemy/exc.py @@ -118,6 +118,10 @@ class ObjectNotExecutableError(ArgumentError): super(ObjectNotExecutableError, self).__init__( "Not an executable object: %r" % target ) + self.target = target + + def __reduce__(self): + return self.__class__, (self.target,) class NoSuchModuleError(ArgumentError): @@ -164,7 +168,11 @@ class CircularDependencyError(SQLAlchemyError): self.edges = edges def __reduce__(self): - return self.__class__, (None, self.cycles, self.edges, self.args[0]) + return ( + self.__class__, + (None, self.cycles, self.edges, self.args[0]), + {"code": self.code} if self.code is not None else {}, + ) class CompileError(SQLAlchemyError): @@ -188,6 +196,12 @@ class UnsupportedCompilationError(CompileError): "Compiler %r can't render element of type %s%s" % (compiler, element_type, ": %s" % message if message else "") ) + self.compiler = compiler + self.element_type = element_type + self.message = message + + def __reduce__(self): + return self.__class__, (self.compiler, self.element_type, self.message) class IdentifierError(SQLAlchemyError): @@ -258,7 +272,7 @@ class ResourceClosedError(InvalidRequestError): object that's in a closed state.""" -class NoSuchColumnError(KeyError, InvalidRequestError): +class NoSuchColumnError(InvalidRequestError, KeyError): """A nonexistent column is requested from a ``Row``.""" @@ -431,8 +445,10 @@ class StatementError(SQLAlchemyError): self.params, self.orig, self.hide_parameters, + self.__dict__.get("code"), self.ismulti, ), + {"detail": self.detail}, ) @_preloaded.preload_module("sqlalchemy.sql.util") @@ -571,8 +587,10 @@ class DBAPIError(StatementError): self.orig, self.hide_parameters, self.connection_invalidated, + self.__dict__.get("code"), self.ismulti, ), + {"detail": self.detail}, ) def __init__( |