Repository navigation
Conversation
…etch A collation callback cannot report an error to SQLite, so the Python exception stays set. A later error in the same step can make sqlite3_step() fail. Then pysqlite_cursor_iternext() calls set_error_from_db() with the exception still set. This causes a SystemError. In debug builds, an assertion fails. _pysqlite_query_execute() already prints or clears the pending exception before it raises the DB-API exception. Move that code into the new helper clear_callback_error() and use it in both functions.
The test compares the printed traceback with plain text. When colors are enabled, the traceback contains escape codes and the comparison fails. Use force_not_colorized to make the output plain.
A collation exception also stays set when the step does not fail. Then pysqlite_cursor_iternext() and executescript() return a result with an exception set. Now the collation exception propagates on these paths. executescript() stops after the statement that caused the exception. It also reports the pending exception when a step fails. Report the pending exception with PyErr_FormatUnraisable() instead of PyErr_Print(). The documentation of enable_callback_tracebacks() says this, and the other callbacks do this. Move the tests into the new class CollationErrorTests and use with_tracebacks().
The failed collation returns a wrong result to SQLite. Thus, the collation exception is the cause of any error later in the step. After each step, check PyErr_Occurred() first and propagate the exception. This also prevents execute() and executemany() from calling converters, adapters and parameter iterators while the exception is set. Other callbacks can run in the same step after the collation raised. Do not call Python code from them while the exception is set. Remove the code that printed or cleared the exception.
The authorizer can run during a step, because table-valued pragma functions prepare statements. inverse() can run after the collation raised, for example when SQLite adds a row to an index that uses the collation. Do not call Python code from these callbacks while an exception is set. final_callback() calls finalize() with the earlier exception set aside. If finalize() raised, the earlier exception was lost. Now the module sets it again, so that it propagates. Make the comments generic, because a callback other than a collation can also leave an exception set. Make the tests check the order of the calls, and add tests for the authorizer, inverse() and finalize().
With STAT4, the query planner can call a collation when SQLite prepares a statement. Check PyErr_Occurred() after sqlite3_prepare_v2() and propagate the exception. Add a control to the authorizer test, so that it shows that SQLite calls the authorizer during the step.
|
Thank you for your interest in contributing to Python. This is a community-driven project, and we want it to be a welcoming place to learn and collaborate. Contributors are responsible for reviewing and understanding what they submit, checking its claims, and being able to explain changes in their own words. This helps reviewers focus on the contribution and leaves more time to support other contributors. This contribution appears to have been authored with AI assistance. Please explain your contribution in your own words and describe how you checked its correctness. Please read our guidelines for using AI tools. |
|
Thank you for your interest in contributing to Python. This is a community-driven project, and we want it to be a welcoming place to learn and collaborate. Contributors are responsible for reviewing and understanding what they submit, checking its claims, and being able to explain changes in their own words. This helps reviewers focus on the contribution and leaves more time to support other contributors. We believe this contribution does not meet our guidelines for using AI tools, so we're closing it. If you think we've misunderstood your contribution, please let us know. You're welcome to explain your approach or ask questions about the guidelines. Please read our guidelines for using AI tools. |
|
This removes |
Withdrawn.