Commit de228781 authored by Vincent Pelletier's avatar Vincent Pelletier

Move _commit_prepare calls deeper in the "try" nesting to make it more robust...

Move _commit_prepare calls deeper in the "try" nesting to make it more robust to errors raised during preparation.
Remove assumtions made on AttributeError in _commit_prepare.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@14036 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent d41aa370
...@@ -78,19 +78,15 @@ try: ...@@ -78,19 +78,15 @@ try:
# do not deadlock. # do not deadlock.
try: try:
ncommitted = 0 ncommitted = 0
jars = self._get_jars(objects, subtransaction)
try:
# Do prepare until number of jars is stable - this could # Do prepare until number of jars is stable - this could
# create infinite loop # create infinite loop
jars_len = -1 jars_len = -1
jars = self._get_jars(objects, subtransaction)
objects_len = len(self._objects)
while len(jars) != jars_len: while len(jars) != jars_len:
jars_len = len(jars) jars_len = len(jars)
self._commit_prepare(jars, subjars, subtransaction) self._commit_prepare(jars, subjars, subtransaction)
if len(self._objects) != objects_len:
objects.extend(self._objects[objects_len:])
objects_len = len(self._objects)
jars = self._get_jars(objects, subtransaction) jars = self._get_jars(objects, subtransaction)
try:
# If not subtransaction, then jars will be modified. # If not subtransaction, then jars will be modified.
self._commit_begin(jars, subjars, subtransaction) self._commit_begin(jars, subjars, subtransaction)
ncommitted += self._commit_objects(objects) ncommitted += self._commit_objects(objects)
...@@ -136,17 +132,15 @@ try: ...@@ -136,17 +132,15 @@ try:
if subtransaction: if subtransaction:
assert not subjars assert not subjars
for jar in jars: for jar in jars:
tpc_prepare = getattr(jar, 'tpc_prepare', None)
if tpc_prepare is not None:
try: try:
jar.tpc_prepare(self, subtransaction) tpc_prepare(self, subtransaction)
except TypeError: except TypeError:
# Assume that TypeError means that tpc_begin() only # Assume that TypeError means that tpc_begin() only
# takes one argument, and that the jar doesn't # takes one argument, and that the jar doesn't
# support subtransactions. # support subtransactions.
jar.tpc_prepare(self) tpc_prepare(self)
except AttributeError:
# Assume that KeyError means that tpc_prepare
# not available
pass
else: else:
# Merge in all the jars used by one of the subtransactions. # Merge in all the jars used by one of the subtransactions.
...@@ -166,15 +160,9 @@ try: ...@@ -166,15 +160,9 @@ try:
# assume that subjars is small, so that it's cheaper to test # assume that subjars is small, so that it's cheaper to test
# whether jar in subjars than to make a dict and do has_key. # whether jar in subjars than to make a dict and do has_key.
for jar in jars: for jar in jars:
#if jar in subjars: tpc_prepare = getattr(jar, 'tpc_prepare', None)
# pass if tpc_prepare is not None:
#else: tpc_prepare(self)
try:
jar.tpc_prepare(self)
except AttributeError:
# Assume that KeyError means that tpc_prepare
# not available
pass
Transaction.Transaction.commit = commit Transaction.Transaction.commit = commit
Transaction.Transaction._commit_prepare = _commit_prepare Transaction.Transaction._commit_prepare = _commit_prepare
......
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