Commit 8c4c5a61 authored by Jim Fulton's avatar Jim Fulton

Fixed: newTransaction was being called in open even in explicit-transaction mode.

parent 48d96cc9
...@@ -902,6 +902,7 @@ class Connection(ExportImport, object): ...@@ -902,6 +902,7 @@ class Connection(ExportImport, object):
# New code is in place. Start a new cache. # New code is in place. Start a new cache.
self._resetCache() self._resetCache()
if not self.explicit_transactions:
# This newTransaction is to deal with some pathalogical cases: # This newTransaction is to deal with some pathalogical cases:
# #
# a) Someone opens a connection when a transaction isn't # a) Someone opens a connection when a transaction isn't
...@@ -915,8 +916,10 @@ class Connection(ExportImport, object): ...@@ -915,8 +916,10 @@ class Connection(ExportImport, object):
# b) Lots of tests assume that connection transaction # b) Lots of tests assume that connection transaction
# information is set on open. # information is set on open.
# #
# Fortunately, this is a cheap operation. It doesn't really # Fortunately, this is a cheap operation. It doesn't
# cost much, if anything. # really cost much, if anything. Well, except for
# RelStorage, in which case it adds a server round
# trip.
self.newTransaction(None, False) self.newTransaction(None, False)
transaction_manager.registerSynch(self) transaction_manager.registerSynch(self)
......
...@@ -1323,7 +1323,25 @@ class TestConnection(unittest.TestCase): ...@@ -1323,7 +1323,25 @@ class TestConnection(unittest.TestCase):
db.close() db.close()
def test_explicit_transactions_no_newTransactuon_on_afterCompletion(self): def test_explicit_transactions_no_newTransactuon_on_afterCompletion(self):
db = ZODB.DB(None) syncs = []
from .MVCCMappingStorage import MVCCMappingStorage
storage = MVCCMappingStorage()
new_instance = storage.new_instance
def new_instance2():
inst = new_instance()
sync = inst.sync
def sync2(*args):
sync()
syncs.append(1)
inst.sync = sync2
return inst
storage.new_instance = new_instance2
db = ZODB.DB(storage)
del syncs[:] # Need to do this to clear effect of getting the
# root object
# We don't want to depend on latest transaction package, so # We don't want to depend on latest transaction package, so
# just set attr for test: # just set attr for test:
...@@ -1331,8 +1349,7 @@ class TestConnection(unittest.TestCase): ...@@ -1331,8 +1349,7 @@ class TestConnection(unittest.TestCase):
tm.explicit = True tm.explicit = True
conn = db.open(tm) conn = db.open(tm)
syncs = [] self.assertEqual(len(syncs), 0)
conn._storage.sync = syncs.append
conn.transaction_manager.begin() conn.transaction_manager.begin()
self.assertEqual(len(syncs), 1) self.assertEqual(len(syncs), 1)
conn.transaction_manager.commit() conn.transaction_manager.commit()
...@@ -1342,17 +1359,18 @@ class TestConnection(unittest.TestCase): ...@@ -1342,17 +1359,18 @@ class TestConnection(unittest.TestCase):
conn.transaction_manager.abort() conn.transaction_manager.abort()
self.assertEqual(len(syncs), 2) self.assertEqual(len(syncs), 2)
conn.close() conn.close()
db.close() self.assertEqual(len(syncs), 2)
# For reference, in non-explicit mode: # For reference, in non-explicit mode:
db = ZODB.DB(None)
conn = db.open() conn = db.open()
self.assertEqual(len(syncs), 3)
conn._storage.sync = syncs.append conn._storage.sync = syncs.append
conn.transaction_manager.begin() conn.transaction_manager.begin()
self.assertEqual(len(syncs), 3)
conn.transaction_manager.abort()
self.assertEqual(len(syncs), 4) self.assertEqual(len(syncs), 4)
conn.transaction_manager.abort()
self.assertEqual(len(syncs), 5)
conn.close() conn.close()
db.close() db.close()
class StubDatabase: class StubDatabase:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment