Skip to content

Commit ada439f

Browse files
committed
Issue #18488: _pysqlite_final_callback() should not clear the exception set by
the last call to the step() method of a user function
1 parent f725dab commit ada439f

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

Modules/_sqlite/connection.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -697,6 +697,7 @@ void _pysqlite_final_callback(sqlite3_context* context)
697697
PyObject** aggregate_instance;
698698
_Py_IDENTIFIER(finalize);
699699
int ok;
700+
PyObject *exception, *value, *tb;
700701

701702
#ifdef WITH_THREAD
702703
PyGILState_STATE threadstate;
@@ -712,7 +713,15 @@ void _pysqlite_final_callback(sqlite3_context* context)
712713
goto error;
713714
}
714715

716+
/* Keep the exception (if any) of the last call to step() */
717+
PyErr_Fetch(&exception, &value, &tb);
718+
715719
function_result = _PyObject_CallMethodId(*aggregate_instance, &PyId_finalize, "");
720+
721+
/* Restore the exception (if any) of the last call to step(),
722+
but clear also the current exception if finalize() failed */
723+
PyErr_Restore(exception, value, tb);
724+
716725
Py_DECREF(*aggregate_instance);
717726

718727
ok = 0;

0 commit comments

Comments
 (0)