This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: sqlite: finalize() method of user function may be called with an exception set if a call to step() method failed
Type: Stage:
Components: Versions: Python 3.4
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: amaury.forgeotdarc, christian.heimes, ghaering, pitrou, python-dev, serhiy.storchaka, vstinner
Priority: normal Keywords:

Created on 2013-07-17 23:39 by vstinner, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (8)
msg193257 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2013-07-17 23:39
In Modules/_sqlite/connection.c, _pysqlite_final_callback() calls the finalize() method of the user function. Calling this method may clear the current exception, whereas test_sqlite excepts that exceptions of step() are reported.
msg193259 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2013-07-17 23:46
New changeset a2214ab0812e by Victor Stinner in branch 'default':
Issue #18488: _pysqlite_final_callback() should not clear the exception set by
msg193260 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2013-07-17 23:56
What is the expected behaviour? Should sqlite call finalize() if step() failed?

If finalize() must be called: which exception should be kept? step() or failure() exception?
msg193269 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2013-07-18 06:58
I think both (PyException_SetContext), as in Python code. See textiowrapper_close() in Modules/_io/textio.c for example.
msg193338 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2013-07-18 23:44
See also isue #18501, similar issue in ElementTree.

I created the issue while working on the issue #18408.
msg193349 - (view) Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * (Python committer) Date: 2013-07-19 08:05
+1 for PyException_SetContext or similar. The C code should behave like a "finally: x.finalize()".
msg193504 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2013-07-22 06:35
New changeset 020dbfdf9517 by Victor Stinner in branch 'default':
Issue #18488: Fix _pysqlite_final_callback()
msg193505 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2013-07-22 06:39
"+1 for PyException_SetContext or similar. The C code should behave like a "finally: x.finalize()"."

If the Python callback failed in _pysqlite_step_callback() or _pysqlite_final_callback(): the exception is printed if sqlite3.enable_callback_tracebacks() has been called, or cleared otherwise.

Only one kind of exception is expected to be passed to be caller (according to sqlite unit tests): AttributeError. The changeset 020dbfdf9517 restores the behaviour of Python 3.3 for best backward compatibility.

If you want better reporting, please open a new issue.

My only concern was just to not call a Python function while an exception is set: I fixed this issue using PyErr_Fetch/PyErr_Restore. So I'm closing the issue.
Date User Action Args
2022-04-11 14:57:48adminsetgithub: 62688
2013-07-22 06:39:08vstinnersetstatus: open -> closed
resolution: fixed
messages: + msg193505
2013-07-22 06:35:19python-devsetmessages: + msg193504
2013-07-19 08:05:48amaury.forgeotdarcsetnosy: + amaury.forgeotdarc
messages: + msg193349
2013-07-18 23:44:37vstinnersetmessages: + msg193338
2013-07-18 06:58:02serhiy.storchakasetmessages: + msg193269
2013-07-17 23:56:18vstinnersetmessages: + msg193260
2013-07-17 23:46:17python-devsetnosy: + python-dev
messages: + msg193259
2013-07-17 23:43:38vstinnersetnosy: + ghaering, pitrou, christian.heimes, serhiy.storchaka
2013-07-17 23:39:52vstinnercreate