diff Modules/_sqlite/connection.c @ 84965:c73f4dced6aa

Issue #18519: Fix test_sqlite on old versions of libsqlite3 With old SQLite versions, _sqlite3_result_error() sets a new Python exception, so don't restore the previous exception.
author Victor Stinner <victor.stinner@gmail.com>
date Fri, 02 Aug 2013 01:48:10 +0200
parents f7a0a4e0ada4
children a04d957c8d07
line wrap: on
line diff
--- a/Modules/_sqlite/connection.c	Fri Aug 02 00:47:47 2013 +0200
+++ b/Modules/_sqlite/connection.c	Fri Aug 02 01:48:10 2013 +0200
@@ -698,6 +698,7 @@
     _Py_IDENTIFIER(finalize);
     int ok;
     PyObject *exception, *value, *tb;
+    int restore;
 
 #ifdef WITH_THREAD
     PyGILState_STATE threadstate;
@@ -715,6 +716,7 @@
 
     /* Keep the exception (if any) of the last call to step() */
     PyErr_Fetch(&exception, &value, &tb);
+    restore = 1;
 
     function_result = _PyObject_CallMethodId(*aggregate_instance, &PyId_finalize, "");
 
@@ -732,11 +734,18 @@
             PyErr_Clear();
         }
         _sqlite3_result_error(context, "user-defined aggregate's 'finalize' method raised error", -1);
+#if SQLITE_VERSION_NUMBER < 3003003
+        /* with old SQLite versions, _sqlite3_result_error() sets a new Python
+           exception, so don't restore the previous exception */
+        restore = 0;
+#endif
     }
 
-    /* Restore the exception (if any) of the last call to step(),
-       but clear also the current exception if finalize() failed */
-    PyErr_Restore(exception, value, tb);
+    if (restore) {
+        /* Restore the exception (if any) of the last call to step(),
+           but clear also the current exception if finalize() failed */
+        PyErr_Restore(exception, value, tb);
+    }
 
 error:
 #ifdef WITH_THREAD