From 22a2fc6aa6d1a64a57be706c88daeae07e43b4fb Mon Sep 17 00:00:00 2001 From: Olivier Dony Date: Thu, 3 Feb 2011 23:51:02 +0100 Subject: [PATCH] [FIX] orm.write: avoid miscalculation of parent_left/right when moving multiple records under same parent This issue caused the parent_left and parent_right values to be correct only for the first record being update as part of a batch update on several children from the same parent. An example of the consequences is the linked bug 708503. lp bug: https://launchpad.net/bugs/708603 fixed bzr revid: odo@openerp.com-20110203225102-a7v8bv90l2ph5ujh --- bin/osv/orm.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/bin/osv/orm.py b/bin/osv/orm.py index 20e7089057d..df458553d3b 100644 --- a/bin/osv/orm.py +++ b/bin/osv/orm.py @@ -3426,14 +3426,19 @@ class orm(orm_template): clause, params = '%s=%%s' % (self._parent_name,), (parent_val,) else: clause, params = '%s IS NULL' % (self._parent_name,), () - cr.execute('SELECT parent_right, id FROM %s WHERE %s ORDER BY %s' % (self._table, clause, order), params) - parents = cr.fetchall() for id in parents_changed: cr.execute('SELECT parent_left, parent_right FROM %s WHERE id=%%s' % (self._table,), (id,)) pleft, pright = cr.fetchone() distance = pright - pleft + 1 + # Positions of current siblings, to locate proper insertion point; + # this can _not_ be fetched outside the loop, as it needs to be refreshed + # after each update, in case several nodes are sequentially inserted one + # next to the other (i.e computed incrementally) + cr.execute('SELECT parent_right, id FROM %s WHERE %s ORDER BY %s' % (self._table, clause, order), params) + parents = cr.fetchall() + # Find Position of the element position = None for (parent_pright, parent_id) in parents: