[pypy-commit] pypy default: Issue1591: sqlite should swallow exceptions raised in adapter.
amauryfa
noreply at buildbot.pypy.org
Mon Aug 26 23:29:12 CEST 2013
Author: Amaury Forgeot d'Arc <amauryfa at gmail.com>
Branch:
Changeset: r66355:6181c1116a92
Date: 2013-08-26 23:27 +0200
http://bitbucket.org/pypy/pypy/changeset/6181c1116a92/
Log: Issue1591: sqlite should swallow exceptions raised in adapter.
diff --git a/lib_pypy/_sqlite3.py b/lib_pypy/_sqlite3.py
--- a/lib_pypy/_sqlite3.py
+++ b/lib_pypy/_sqlite3.py
@@ -1229,7 +1229,10 @@
if cvt is not None:
param = cvt(param)
- param = adapt(param)
+ try:
+ param = adapt(param)
+ except:
+ pass # And use previous value
if param is None:
rc = _lib.sqlite3_bind_null(self._statement, idx)
diff --git a/pypy/module/test_lib_pypy/test_sqlite3.py b/pypy/module/test_lib_pypy/test_sqlite3.py
--- a/pypy/module/test_lib_pypy/test_sqlite3.py
+++ b/pypy/module/test_lib_pypy/test_sqlite3.py
@@ -228,3 +228,18 @@
cur = con.cursor()
cur.execute(u'SELECT 1 as méil')
assert cur.description[0][0] == u"méil".encode('utf-8')
+
+def test_adapter_exception(con):
+ def cast(obj):
+ raise ZeroDivisionError
+
+ _sqlite3.register_adapter(int, cast)
+ try:
+ cur = con.cursor()
+ cur.execute("select ?", (4,))
+ val = cur.fetchone()[0]
+ # Adapter error is ignored, and parameter is passed as is.
+ assert val == 4
+ assert type(val) is int
+ finally:
+ del _sqlite3.adapters[(int, _sqlite3.PrepareProtocol)]
More information about the pypy-commit
mailing list