Author: phd
Date: 2006-08-04 09:09:48 -0600 (Fri, 04 Aug 2006)
New Revision: 1846
Modified:
home/phd/SQLObject/paramstyles/sqlobject/dbconnection.py
home/phd/SQLObject/paramstyles/sqlobject/tests/test_transactions.py
Log:
Merged patches from the revisions 1836:1845 from the trunk
Modified: home/phd/SQLObject/paramstyles/sqlobject/dbconnection.py
===================================================================
--- home/phd/SQLObject/paramstyles/sqlobject/dbconnection.py 2006-08-04 04:04:45 UTC (rev 1845)
+++ home/phd/SQLObject/paramstyles/sqlobject/dbconnection.py 2006-08-04 15:09:48 UTC (rev 1846)
@@ -798,12 +798,14 @@
class Transaction(object):
def __init__(self, dbConnection):
- self._obsolete = False
+ # this is to skip __del__ in case of an exception in this __init__
+ self._obsolete = True
self._dbConnection = dbConnection
self._connection = dbConnection.getConnection()
self._dbConnection._setAutoCommit(self._connection, 0)
self.cache = CacheSet(cache=dbConnection.doCache)
self._deletedCache = {}
+ self._obsolete = False
def assertActive(self):
assert not self._obsolete, "This transaction has already gone through ROLLBACK; begin another transaction"
@@ -850,8 +852,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:
@@ -859,6 +859,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:
Modified: home/phd/SQLObject/paramstyles/sqlobject/tests/test_transactions.py
===================================================================
--- home/phd/SQLObject/paramstyles/sqlobject/tests/test_transactions.py 2006-08-04 04:04:45 UTC (rev 1845)
+++ home/phd/SQLObject/paramstyles/sqlobject/tests/test_transactions.py 2006-08-04 15:09:48 UTC (rev 1846)
@@ -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)
|