[DB-SIG] Adding Connection.autocommit as standard extension to DB-API 2.0 (PEP 249)

Mike Bayer mike_mp at zzzcomputing.com
Fri Oct 28 10:14:54 EDT 2022



On Fri, Oct 28, 2022, at 10:06 AM, Marc-Andre Lemburg wrote:
> On 28.10.2022 16:02, Mike Bayer wrote:
> > 
> > 
> > On Fri, Oct 28, 2022, at 9:58 AM, Marc-Andre Lemburg wrote:
> >> If there is a pending transaction, though, there are three approaches
> >> we could take:
> >>
> >> 1. The database module raises an exception, to force an explicit
> >>     .commit() or .rollback() by the programmer.
> >>
> >> 2. The module automatically commits the pending transaction,
> >>     since that's what autocommit is all about.
> >>
> >> 3. We leave these semantics open and up to the database module
> >>     to determine.
> >>
> >> My preference would be option 2, since this makes things clear for
> >> everyone and is intuitive (well, at least for me :-)).
> > 
> > option 3 is likely what will occur in practice.   it feels a little 
> > awkward for an attribute set operation to move forward with a 
> > transactional modification to the database server.
> 
> Think of this as a property, which is how many database modules
> will implement it.
> 
> I agree that it feels a bit awkward, especially since setting
> an attribute should normally not cause exceptions, but it's become
> a standard among modules nonetheless (I don't remember who started
> with it).


well, an exception saying, "I'm not going to commit the transaction here, please call commit() or rollback() first" is of much narrower scope than one that went all the way out to the database to commit a transaction, which then failed.   Or worse, some routine that sets .autocommit as a matter of course ends up causing network round trips in an unexpected place.    

I think the bigger issue here is that this proposes allowing network IO to occur by setting an attribute.   I know this is of course *possible* but this is not considered to be a good practice, particularly in the age of asyncio (which I know, DBAPI is not asyncio, but these things still have interactions in practice).

The precedent however is that DBAPIs take lots of liberties with things whether the DBAPI spec allows them to or not.    
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.python.org/pipermail/db-sig/attachments/20221028/55d98d11/attachment-0001.html>


More information about the DB-SIG mailing list