summaryrefslogtreecommitdiff
path: root/test/engine/test_execute.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2012-01-10 11:15:11 -0500
committerMike Bayer <mike_mp@zzzcomputing.com>2012-01-10 11:15:11 -0500
commitd78d2d60aa30b0b6c3c230ddf3cafda2529e6409 (patch)
tree860e40ae961ba38a8a4130738d562488b5a67d0e /test/engine/test_execute.py
parent88ac77bc56931c7d43756e2e2c6c537375d1b57b (diff)
downloadsqlalchemy-d78d2d60aa30b0b6c3c230ddf3cafda2529e6409.tar.gz
- [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]
Diffstat (limited to 'test/engine/test_execute.py')
-rw-r--r--test/engine/test_execute.py37
1 files changed, 37 insertions, 0 deletions
diff --git a/test/engine/test_execute.py b/test/engine/test_execute.py
index 49457644a..eaef9e43a 100644
--- a/test/engine/test_execute.py
+++ b/test/engine/test_execute.py
@@ -1,5 +1,6 @@
from test.lib.testing import eq_, assert_raises, assert_raises_message, config
import re
+from test.lib.util import picklers
from sqlalchemy.interfaces import ConnectionProxy
from sqlalchemy import MetaData, Integer, String, INT, VARCHAR, func, \
bindparam, select, event, TypeDecorator
@@ -188,6 +189,42 @@ class ExecuteTest(fixtures.TestBase):
finally:
conn.close()
+ def test_stmt_exception_pickleable_no_dbapi(self):
+ self._test_stmt_exception_pickleable(Exception("hello world"))
+
+ @testing.fails_on("postgresql+psycopg2",
+ "Packages the cursor in the exception")
+ def test_stmt_exception_pickleable_plus_dbapi(self):
+ raw = testing.db.raw_connection()
+ try:
+ cursor = raw.cursor()
+ cursor.execute("SELECTINCORRECT")
+ except testing.db.dialect.dbapi.DatabaseError, orig:
+ pass
+ finally:
+ raw.close()
+ self._test_stmt_exception_pickleable(orig)
+
+ def _test_stmt_exception_pickleable(self, orig):
+ for sa_exc in (
+ tsa.exc.StatementError("some error",
+ "select * from table",
+ {"foo":"bar"},
+ orig),
+ tsa.exc.InterfaceError("select * from table",
+ {"foo":"bar"},
+ orig),
+ ):
+ for loads, dumps in picklers():
+ repickled = loads(dumps(sa_exc))
+ eq_(repickled.message, sa_exc.message)
+ eq_(repickled.params, {"foo":"bar"})
+ eq_(repickled.statement, sa_exc.statement)
+ if hasattr(sa_exc, "connection_invalidated"):
+ eq_(repickled.connection_invalidated,
+ sa_exc.connection_invalidated)
+ eq_(repickled.orig.message, orig.message)
+
def test_dont_wrap_mixin(self):
class MyException(Exception, tsa.exc.DontWrapMixin):
pass