#69 Transaction.commit(close=True) fails to synchronize deletes

closed-accepted
Oleg Broytman
None
5
2006-08-09
2006-07-18
Luke Opperman
No

With close=True, Transaction.commit() calls
_makeObsolete before synchronizing the main connection
cache - this resets Transaction._deletedCache, so
objects deleted in the transaction are never expired.

Test and fix below:

Index: dbconnection.py

--- dbconnection.py (revision 1827)
+++ dbconnection.py (working copy)
@@ -837,8 +837,6 @@
if self._dbConnection.debug:

self._dbConnection.printDebug(self._connection, '',
'COMMIT')
self._connection.commit()
- if close:
- self._makeObsolete()
subCaches = [(sub[0], sub[1].allIDs()) for sub
in self.cache.allSubCachesByClassNames().items()]
subCaches.extend([(x[0], x[1]) for x in
self._deletedCache.items()])
for cls, ids in subCaches:
@@ -846,6 +844,8 @@
inst =
self._dbConnection.cache.tryGetByName(id, cls)
if inst is not None:
inst.expire()
+ if close:
+ self._makeObsolete()

def rollback(self):
if self._obsolete:
Index: tests/test_transactions.py
===================================================================
--- tests/test_transactions.py (revision 1827)
+++ tests/test_transactions.py (working copy)
@@ -52,7 +52,7 @@
finally:
TestSOTrans._connection.autoCommit = True

-def test_transaction_delete():
+def test_transaction_delete(close=False):
if not supports('transactions'):
return
setupClass(TestSOTrans)
@@ -63,5 +63,14 @@
bIn.destroySelf()
bOut =
TestSOTrans.select(TestSOTrans.q.name=='bob')
assert bOut.count() == 1
+ bOutInst = bOut[0]
+ bOutID = bOutInst.id
+ trans.commit(close=close)
+ assert bOut.count() == 0
+ raises(SQLObjectNotFound,
"TestSOTrans.get(bOutID)")
+ raises(SQLObjectNotFound, "bOutInst.name")
finally:
TestSOTrans._connection.autoCommit = True
+
+def test_transaction_delete_with_close():
+ test_transaction_delete(close=True)

Discussion

  • Luke Opperman
    Luke Opperman
    2006-07-18

     
    Attachments
  • Oleg Broytman
    Oleg Broytman
    2006-08-09

    Logged In: YES
    user_id=4799

    Applied at rev. 1840. Thank you!

     
  • Oleg Broytman
    Oleg Broytman
    2006-08-09

    • assigned_to: nobody --> phd
    • status: open --> closed-accepted