diff options
| author | Olivier Dony <odo@openerp.com> | 2011-02-03 23:51:02 +0100 |
|---|---|---|
| committer | Olivier Dony <odo@openerp.com> | 2011-02-03 23:51:02 +0100 |
| commit | 22a2fc6aa6d1a64a57be706c88daeae07e43b4fb (patch) | |
| tree | e92fde6443a8d94689b35bdf4877eddc9cab1c93 /bin | |
| parent | 153238a6661cee61dbc79dc7adb29123df3b6671 (diff) | |
[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
Diffstat (limited to 'bin')
| -rw-r--r-- | bin/osv/orm.py | 9 |
1 files 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: |
