[DB-SIG] DB API compliance test--clarification
M.-A. Lemburg
mal@lemburg.com
Mon, 17 Feb 2003 09:00:39 +0100
David Rushby wrote:
> Code snippet from Stuart's DB API compliance suite:
>
> -----------
> def test_commit(self):
> con = self._connect()
> try:
> # Commit must work, even if it doesn't do anything
> con.commit()
> finally:
> con.close()
> -----------
>
> Is it reasonable to commit a transaction without ever having created
> it?
You create the transaction implicitly by connecting to the database.
> It seems to me that this behavior is likely to give rise to subtle
> errors, as when the programmer thinks he's made some changes to the
> database without having actually done so (without even having
> established a transaction), and the commit() call doesn't complain
> about the lack of an active transaction.
>
> kinterbasdb (Interbase/Firebird driver) currently raises the following
> exception in this situation:
>
> ProgrammingError: (-901, 'There is no active transaction to commit.
> Consider using begin() to explicitly start a transaction in advance of
> this commit() call.')
>
> If allow-commit-of-a-nonexistent-transaction is really the convention
> in the Python DB API community, I'll change kinterbasdb to conform to
> it, but I don't like it.
Opening a connection implicitly starts a transaction and all
calls to .commit() and .rollback() do the same. There never is
a state which you could call "non-existent transaction" (and that's
good :-).
--
Marc-Andre Lemburg
eGenix.com
Professional Python Software directly from the Source (#1, Feb 17 2003)
>>> Python/Zope Products & Consulting ... http://www.egenix.com/
>>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/
________________________________________________________________________
Python UK 2003, Oxford: 43 days left
EuroPython 2003, Charleroi, Belgium: 127 days left