-
-
Notifications
You must be signed in to change notification settings - Fork 31.9k
bpo-45089: raise exceptions on error in sqlite3
trace callback
#28133
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
144f31d
to
0af5288
Compare
I see no way to test |
@serhiy-storchaka I would like your opinion on this PR, if you don't mind. |
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, traceback
PyErr_Fetch(&type, &value, &traceback);
pysqlite_state *state = pysqlite_get_state(NULL);
if (state->enable_callback_tracebacks) {
// Get extra references to type, value & traceback
Py_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. |
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. |
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