From d78d2d60aa30b0b6c3c230ddf3cafda2529e6409 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Tue, 10 Jan 2012 11:15:11 -0500 Subject: - [bug] Added __reduce__ to StatementError, DBAPIError so that exceptions are pickleable, as when using multiprocessing. However, not all DBAPIs support this yet, such as psycopg2. [ticket:2371] --- lib/sqlalchemy/exc.py | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'lib/sqlalchemy') diff --git a/lib/sqlalchemy/exc.py b/lib/sqlalchemy/exc.py index 59a15f079..55205b274 100644 --- a/lib/sqlalchemy/exc.py +++ b/lib/sqlalchemy/exc.py @@ -164,6 +164,10 @@ class StatementError(SQLAlchemyError): self.params = params self.orig = orig + def __reduce__(self): + return self.__class__, (self.message, self.statement, + self.params, self.orig) + def __str__(self): from sqlalchemy.sql import util params_repr = util._repr_params(self.params, 10) @@ -219,6 +223,10 @@ class DBAPIError(StatementError): return cls(statement, params, orig, connection_invalidated) + def __reduce__(self): + return self.__class__, (self.statement, self.params, + self.orig, self.connection_invalidated) + def __init__(self, statement, params, orig, connection_invalidated=False): try: text = str(orig) -- cgit v1.2.1