Python Forum
Is there a standard for autocommit In PEP 249
Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Is there a standard for autocommit In PEP 249
#1
I tried reading PEP 249 and I could not locate any mentioning as a parameter to the connect() except in the commit method:
----------------------------
.commit()
Commit any pending transaction to the database.

Note that if the database supports an auto-commit feature, this must be initially off. An interface method may be provided to turn it back on.

Database modules that do not support transactions should implement this method with void functionality.
----------------------------
Other languages do supply that as an option. Is there anything special in Python that obviate the need to set this option, either in the connect or elsewhere?

Thanks
ZA

Could somebody help me. This need to be moved to 'general coding help' and I do not know how to do it
Thank you
Reply
#2
Don't know what you're reading, PEP 249 has a huge section labeled 'Connection Objects'
Reply
#3
This DOES NOT answer the question!

1. The description of 'commit()' in my original post is the second item in the 'connection objects' section, so obviously, I read PEP 249 and specifically, the recommended section.

2. Nowhere in that section or anywhere else, there is any reference for a standard way to provide the autocommit option! At least not any reference that is obvious.

Autocommit is a standard feature in Perl's DBI, Java's JDBC and ODBC for example. So, either the Python guys believe that they know better than the rest of the world (I doubt that they believe it and I doubt that they are), or, I miss something... and I asked to point me where is that feature mentioned.


Thank you
ZA
Reply
#4
(Feb-05-2019, 06:38 PM)zatlas1 Wrote: I tried reading PEP 249 and I could not locate any mentioning as a parameter to the connect()

I am not familiar with the subject but I read following mentioning of connect parameters from PEP 249:

Quote:As a guideline the connection constructor parameters should be implemented as keyword parameters for more intuitive use and follow this order of parameters:

Parameter Meaning
dsn Data source name as string
user User name as string (optional)
password Password as string (optional)
host Hostname (optional)
database Database name (optional)
E.g. a connect could look like this:

connect(dsn='myhost:MYDB', user='guido', password='234$')
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy

Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Reply
#5
You are right that there isn't a lot about autocommit.
I did find one reference that states it is done by appending autocommit to the connection:

conn = MySQLdb.connect(...)
conn.autocommit(True)
Reply
#6
Almost all databases support auto-commit,just that is off bye default in most cases for Python,as mention in 249.
PEP 249 Wrote:Note that if the database supports an auto-commit feature, this must be initially off. An interface method may be provided to turn it back on.
There is a reason behind this from mailing list,long time ago:
Quote:Auto commit is a bad thing and a pretty evil invention of ODBC.
While it does make writing ODBC drivers simpler (ones which don't support transactions that is),
it is potentially dangerous at times, e.g. take a crashing program: there is no way to recover from errors because the database has no way of knowing which data is valid and which is not.
No commercial application handling "mission critical" (I love that term ;-) data would ever want to run in auto-commit mode.
Quote:ANY serious application MUST manage its own transactions, as otherwise you can't ever hope to control failure modes.
Python developers took this sort of information into consideration and decided the benefit of having auto-commit off by default (easier error handling and reversing).

That said it's very easy to turn on in almost all cases.
# PostgreSQL
conn.set_session(readonly=True, autocommit=True)

# For Flask-SQLAlchemy(what i use most)
db = SQLAlchemy(app, session_options={'autocommit': True})
SQLAlchemy Python biggest ORM,dos implements it's own auto-commit.
Understanding Autocommit
Quote:SQLAlchemy implements its own “autocommit” feature which works completely consistently across all backends
Reply
#7
There is a fundamental issue with PEP 249 regarding this common feature. I truly expected without any prejudice, that I would find a reference to autocommit in the PEP. Something like this imaginary paragraph:
Quote:autocommit is an attribute that means bla bla bla. By default it should be set to false because of bla bla bla. You could set it to whatever you want in connection time or dynamically later, by specifying:
whatefer.autocommit(true) or something else...
[as you see above in the thread, there were two non-standard flavors mentioned (MySQL and Postgress) and who knows how many other flavors are out there. So I would expect the standard to specify one of them as the choice flavor whatever the standard bearer have decided is best.]
The authors of the standard chose to leave that out of the standard altogether and allow a wild west of options. In my case I have to do connections to Oracle, Sybase ASE, Sybase Anywhere, Postgress and potentially SQL Server and a couple of other databases, and many times more than one or two concurrently. So the poor programmer who wants to set autocommit on or off. has to remember five different non-standard ways of doing so.
What could I say (with a lot of sarcasm), what a great design or lack of it thereof!
Reply
#8
(Feb-06-2019, 02:56 PM)zatlas1 Wrote: that I would find a reference to autocommit in the PEP.
There is a reference as i posted over,the default for Python is auto-commit off.
If database authors follow this Python standard is up to them.
They can have there own reason not to,then it should be clear in there documentation.
PEP 249 Wrote:Note that if the database supports an auto-commit feature,this must be initially off. An interface method may be provided to turn it back on.
Reply
#9
Don't misunderstand me, I will follow all my vendors' documentation, deal with it, and hide that from my users' (I am writing a common connect/interface class), but I still think that there should have been a common way to express autocommit (regardless of the choice of default), akin to other languages' API's.
Now I know that the Python guys believe that they are better than anybody else. Such hubris is in the eyes of the beholder.
Reply
#10
(Feb-06-2019, 03:55 PM)zatlas1 Wrote: Now I know that the Python guys believe that they are better than anybody else
I have always though that C++ people hold that merit Wink
As i been told many times in the past to use a real programming language.
Quote:Yes, we C++ programmers look down on all others as lesser beings.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How psycopg2 autocommit works ? johntay 3 10,195 Oct-08-2021, 11:22 AM
Last Post: Larz60+
  Winsorized Mean and Standard Deviation Wheeliam 0 1,791 Jul-11-2020, 05:27 PM
Last Post: Wheeliam
  standard library modules chpyel 4 2,761 May-10-2020, 02:58 PM
Last Post: snippsat
  Graphics and standard deviation rocioaraneda 3 2,671 Jan-09-2019, 10:53 PM
Last Post: micseydel
  standard data types rombertus 3 51,329 Dec-23-2018, 08:52 PM
Last Post: rombertus
  Standard library code BerryK 2 3,984 Apr-29-2017, 10:32 PM
Last Post: Larz60+
  what is my standard in python currently? hsunteik 3 3,697 Jan-19-2017, 12:37 PM
Last Post: metulburr

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020