Uh oh!
There was an error while loading. Please reload this page.
bpo-45089: raise exceptions on error in sqlite3 trace callback - #28133
bpo-45089: raise exceptions on error in sqlite3 trace callback#28133erlend-aasland wants to merge 3 commits into
sqlite3 trace callback#28133Conversation
144f31d to
0af5288Compareerlend-aasland
commented
Sep 2, 2021
I see no way to test |
erlend-aasland
commented
Sep 3, 2021
@serhiy-storchaka I would like your opinion on this PR, if you don't mind. |
encukou
commented
Sep 7, 2021
I assumed exceptions in a trace function were ignored on purpose, since there's no way to inform SQLite of the error? It would be nice to chain the original exception. It's a bit complicated to combine it with the PyObject*type, *value, *traceback;
// Clear the error indicator; get references to type, value, tracebackPyErr_Fetch(&type, &value, &traceback);
pysqlite_state*state=pysqlite_get_state(NULL);
if (state->enable_callback_tracebacks) {
// Get extra references to type, value & tracebackPy_INCREF(type);
Py_INCREF(value);
Py_INCREF(traceback);
// Restore the error indicator (losing the extra references)PyErr_Restore(type, value, traceback);
// Print the error (clearing the error indicator)PyErr_Print();
}
PyErr_SetString(state->OperationalError,
"trace callback raised an exception");
// Chain the original exception as __cause__ (losing our references)_PyErr_ChainExceptions(type, value, traceback);And since since the user will get the original exception, I wonder if the printing could be skipped. |
Maybe so, but how else should we inform the user about bugs in trace functions if not through exceptions?
Yes, good point. |
encukou
commented
Sep 7, 2021
AFAIK,
It is: Without the ability to tell SQLite to abort on trace failure, I doubt we can do much better than the current behavior. Getting an exception and having the data inserted seems quite irregular. |
erlend-aasland
commented
Sep 7, 2021
Well, it kinda works, but you won't get an exception. However, getting an exception and having the database modified is worse.
I do agree. |
https://bugs.python.org/issue45089