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.

Author mdk
Recipients inglesp, mdk
Date 2016-11-18.22:40:09
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1479508809.88.0.848909305689.issue28729@psf.upfronthosting.co.za>
In-reply-to
Content
By moving:

```
/* else set the right exception and return NULL */
PyErr_SetString(pysqlite_ProgrammingError, "can't adapt");
```

from `pysqlite_microprotocols_adapt` to `pysqlite_adapt` (to avoid changing the semantics from the outside) make the `pysqlite_microprotocols_adapt`protocol clearer:
 - if it went well return something
 - If it went well but had nothing to do: return NULL
 - If it broke, set an exception and return NULL

It does not break any test. Then in `Modules/_sqlite/statement.c`, we can stop blindly muting exceptions with the `PyErr_Clear`s, replacing them with ``if (PyErr_Occurred()) return;``. Again it does not break any test.

I added a test to check that if an adapter raises an exception it bubbles outside the execute method, and it passes.

Sample code given by the issue now gives::

   $ ./python issue28729.py 
   Traceback (most recent call last):
     File "issue28729.py", line 18, in <module>
       cur.execute("select ?", (p,))
     File "issue28729.py", line 10, in adapt_point
       assert False, 'Problem in adapter'
   AssertionError: Problem in adapter

I did not found precise documentation about pysqlite_microprotocols_adapt or pysqlite_adapt, so my changes may break a "well known protocol", but it looks safe as I do not change the _sqlite protocol as far as I can tell, (only when the exception comes directly from the adaptor, obviously), and there were no other uses of pysqlite_microprotocols_adapt, which is not exposed in the module.
History
Date User Action Args
2016-11-18 22:40:09mdksetrecipients: + mdk, inglesp
2016-11-18 22:40:09mdksetmessageid: <1479508809.88.0.848909305689.issue28729@psf.upfronthosting.co.za>
2016-11-18 22:40:09mdklinkissue28729 messages
2016-11-18 22:40:09mdkcreate