Skip to content

Add optional Connection.autocommit attribute to PEP 249 #2887

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

Merged
merged 3 commits into from
Nov 16, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 52 additions & 9 deletions pep-0249.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Discussions-To: db-sig@python.org
Status: Final
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this PEP is Informational, shouldn't it be Active, givens the guidance within is presumably still valid, up to date and in-use rather than historical and frozen?

Type: Informational
Content-Type: text/x-rst
Created: 29-Mar-2001
Created: 12-Apr-1999
Post-History:
Replaces: 248

Expand Down Expand Up @@ -932,6 +932,34 @@ Cursor\ `.lastrowid`_
*Warning Message:* "DB-API extension cursor.lastrowid used"


.. _Connection.autocommit:
.. _.autocommit:

Connection\ `.autocommit`_
Attribute to query and set the autocommit mode of the connection.

Return ``True`` if the connection is operating in autocommit (non-
transactional) mode. Return ``False`` if the connection is
operating in manual commit (transactional) mode.

Setting the attribute to ``True`` or ``False`` adjusts the
connection's mode accordingly.

Changing the setting from ``True`` to ``False`` (disabling
autocommit) will have the database leave autocommit mode and start
a new transaction. Changing from ``False`` to ``True`` (enabling
autocommit) has database dependent semantics with respect to how
pending transactions are handled. [12]_

*Deprecation notice*: Even though several database modules implement
both the read and write nature of this attribute, setting the
autocommit mode by writing to the attribute is deprecated, since
this may result in I/O and related exceptions, making it difficult
to implement in an async context. [13]_

*Warning Message:* "DB-API extension connection.autocommit used"


Optional Error Handling Extensions
==================================

Expand Down Expand Up @@ -1232,6 +1260,8 @@ Footnotes

connect(dsn='myhost:MYDB', user='guido', password='234$')

Also see [13]_ regarding planned future additions to this list.

.. [2] Module implementors should prefer ``numeric``, ``named`` or
``pyformat`` over the other formats because these offer more
clarity and flexibility.
Expand All @@ -1241,10 +1271,10 @@ Footnotes
the method, the interface should throw an exception in case the
method is used.

The preferred approach is to not implement the method and thus
have Python generate an ``AttributeError`` in case the method is requested. This
allows the programmer to check for database capabilities using the
standard ``hasattr()`` function.
The preferred approach is to not implement the method and thus have
Python generate an ``AttributeError`` in case the method is
requested. This allows the programmer to check for database
capabilities using the standard ``hasattr()`` function.

For some dynamically configured interfaces it may not be
appropriate to require dynamically making the method
Expand Down Expand Up @@ -1309,20 +1339,33 @@ Footnotes
the time of writing of the DB-API 2.0 in 1999, the warning framework
in Python did not yet exist.

.. [12] Many database modules implementing the autocommit attribute will
automatically commit any pending transaction and then enter
autocommit mode. It is generally recommended to explicitly
`.commit()`_ or `.rollback()`_ transactions prior to changing the
autocommit setting, since this is portable across database modules.

.. [13] In a future revision of the DB-API, we are going to introduce a
new method ``.setautocommit(value)``, which will allow setting the
autocommit mode, and make ``.autocommit`` a read-only attribute.
Additionally, we are considering to add a new standard keyword
parameter ``autocommit`` to the Connection constructor. Modules
authors are encouraged to add these changes in preparation for this
change.

Acknowledgements
================

Many thanks go to Andrew Kuchling who converted the Python Database
API Specification 2.0 from the original HTML format into the PEP
format.
format in 2001.

Many thanks to James Henstridge for leading the discussion which led
to the standardization of the two-phase commit API extensions.
Many thanks to James Henstridge for leading the discussion which led to
the standardization of the two-phase commit API extensions in 2008.

Many thanks to Daniele Varrazzo for converting the specification from
text PEP format to ReST PEP format, which allows linking to various
parts.
parts in 2012.

Copyright
=========
Expand Down