Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

#3 Bug in the release of a transaction connection

closed
Oleg Broytman
None
5
2006-02-06
2005-12-06
Hong Yuan
No

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
the Transaction
class. The following is what happens:

1. A transaction object is created. The corresponding
physical
database connection is set to autommit=0 by
self._dbConnection._setAutoCommit(self._connection, 0) in
Transaction.__init__.

2. The processing with the transaction is finished.
Transaction object
is deleted. The physical database connection is
returned to the pool
using self._dbConnection.releaseConnection in the method
_makeObsolete. However, the connection still has
autommit=0.

3. A new SQLObject is to be created. The
_SO_finishCreate method calls
_queryInsertID to inert the data. _queryInsertID gets a
physical
connection from the pool, which happens to be the one
just returned by
the transaction, i.e. with autocommit=0. This means the
INSERT SQL
will not automatically commit. The transaction is still
in progress
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.
However,
_SO_selectOne gets another physical database connection
from the pool,
and can therefore not see the new data just inserted.
It raises
SQLObjectNotFound.

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
not restored.

I made the following patch to dbconnection.py and my
problem is gone.

Can anyone check my diagnosis and the fix?

Index: dbconnection.py

===================================================================

--- dbconnection.py (revision 1334)

+++ dbconnection.py (working copy)

@@ -857,6 +857,8 @@

def _makeObsolete(self):
self._obsolete = True
+ if self._dbConnection.autoCommit:
+
self._dbConnection._setAutoCommit(self._connection, 1)

self._dbConnection.releaseConnection(self._connection,
explicit=True)
self._connection = None

Discussion

  • Oleg Broytman
    Oleg Broytman
    2006-01-30

    Logged In: YES
    user_id=4799

    With the patch test_transaction.py fails. Can you check if
    it's a bug in the test_transaction.py or a problem with the
    patch?

     
  • Oleg Broytman
    Oleg Broytman
    2006-02-06

    • assigned_to: nobody --> phd
    • status: open --> closed
     
  • Oleg Broytman
    Oleg Broytman
    2006-02-06

    Logged In: YES
    user_id=4799

    A corrected version has been applied to the trunk at the
    revision 1578.