In one of my application using SQLObject, I found that
once I have
used a transaction, the next insert with an auto
sequence will fail.
Debugging the code, I suspect this could be a bug in
class. The following is what happens:
1. A transaction object is created. The corresponding
database connection is set to autommit=0 by
self._dbConnection._setAutoCommit(self._connection, 0) in
2. The processing with the transaction is finished.
is deleted. The physical database connection is
returned to the pool
using self._dbConnection.releaseConnection in the method
_makeObsolete. However, the connection still has
3. A new SQLObject is to be created. The
_SO_finishCreate method calls
_queryInsertID to inert the data. _queryInsertID gets a
connection from the pool, which happens to be the one
just returned by
the transaction, i.e. with autocommit=0. This means the
will not automatically commit. The transaction is still
when _SO_finishCreate returns.
4. _init(id) is called. It calls _SO_selectOne to see
if the data with
the given ID is actually inserted into the database.
_SO_selectOne gets another physical database connection
from the pool,
and can therefore not see the new data just inserted.
The problem is during transaction creatiion, the
autocommit status of
the physical database connection has been changed. But when
transaction object is deleted, the original status is
I made the following patch to dbconnection.py and my
problem is gone.
Can anyone check my diagnosis and the fix?
--- dbconnection.py (revision 1334)
+++ dbconnection.py (working copy)
@@ -857,6 +857,8 @@
self._obsolete = True
+ if self._dbConnection.autoCommit:
self._connection = None
Log in to post a comment.