[FIX] orm.write: avoid miscalculation of parent_left/right when moving multiple recor...
authorOlivier Dony <odo@openerp.com>
Thu, 3 Feb 2011 22:51:02 +0000 (23:51 +0100)
committerOlivier Dony <odo@openerp.com>
Thu, 3 Feb 2011 22:51:02 +0000 (23:51 +0100)
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

index 20e7089..df45855 100644 (file)
@@ -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: