From c2ed78f3a738624bde95b164b6aa0e55aa2851a0 Mon Sep 17 00:00:00 2001 From: Yoshinori Okuji <yo@nexedi.com> Date: Sat, 29 Sep 2007 03:50:06 +0000 Subject: [PATCH] Fix a serious mistake which led to committing the same object twice. Also, remove an unnecessary piece of code. git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@16719 20353a03-c40f-0410-a6d1-a30d3c3de9de --- product/ERP5Type/patches/Transaction.py | 33 +++++++++---------------- 1 file changed, 11 insertions(+), 22 deletions(-) diff --git a/product/ERP5Type/patches/Transaction.py b/product/ERP5Type/patches/Transaction.py index 52ebe26543..ddbe2a8cb8 100644 --- a/product/ERP5Type/patches/Transaction.py +++ b/product/ERP5Type/patches/Transaction.py @@ -83,13 +83,9 @@ try: # Do prepare until number of jars is stable - this could # create infinite loop jars_len = -1 - objects_len = len(self._objects) while len(jars) != jars_len: jars_len = len(jars) 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) # If not subtransaction, then jars will be modified. self._commit_begin(jars, subjars, subtransaction) @@ -146,28 +142,21 @@ try: # support subtransactions. tpc_prepare(self) else: - # Merge in all the jars used by one of the subtransactions. - - # When the top-level subtransaction commits, the tm must - # call commit_sub() for each jar involved in one of the - # subtransactions. The commit_sub() method should call - # tpc_begin() on the storage object. - - # It must also call tpc_begin() on jars that were used in - # a subtransaction but don't support subtransactions. - - # These operations must be performed on the jars in order. - - # Modify jars inplace to include the subjars, too. - jars += subjars - jars.sort(jar_cmp) - # 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. - for jar in jars: + # Perform tpc_prepare for both jars and subjars. + # Note that it must not be executed for the same jar + # more than once. Also, this should not merge the jars + # in place, as _commit_begin will do that. + for jar in subjars: tpc_prepare = getattr(jar, 'tpc_prepare', None) if tpc_prepare is not None: tpc_prepare(self) + for jar in jars: + if jar not in subjars: + tpc_prepare = getattr(jar, 'tpc_prepare', None) + if tpc_prepare is not None: + tpc_prepare(self) + Transaction.Transaction.commit = commit Transaction.Transaction._commit_prepare = _commit_prepare except ImportError: -- 2.30.9