summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRaphael Collet <rco@openerp.com>2015-09-08 15:09:35 +0200
committerRaphael Collet <rco@openerp.com>2015-09-09 09:36:40 +0200
commit085875619fbbebfcb1a4e6bb4ff28d109bd4b07b (patch)
treeb557b82344b97002d36516d516511c593a0518bf
parentb89b7e0554d05e90965f31f80b22fe98f2f4b239 (diff)
[FIX] fields: in `one2many.set`, replace incorrect query by ORM access
When linking a record into a `one2many` relation with command `(4, rid)`, a query checks whether the record is already linked to the current record id: SELECT 1 FROM {inv_table} WHERE id={rid} AND {inv_field}={id} where `inv_field` is the name of the inverse field, and `inv_table` is the table where this field is stored. The query is wrong if the inverse field is inherited, because the `rid` does not belong to the table `inv_table`. The test has been replaced by a plain ORM access: rec = obj.browse(cr, SUPERUSER_ID, rid) if int(rec[inv_field]) != id: ... This fixes #4685.
-rw-r--r--openerp/osv/fields.py9
1 files changed, 3 insertions, 6 deletions
diff --git a/openerp/osv/fields.py b/openerp/osv/fields.py
index 3b7a18edf53..76aecfe2b84 100644
--- a/openerp/osv/fields.py
+++ b/openerp/osv/fields.py
@@ -823,12 +823,9 @@ class one2many(_column):
else:
cr.execute('update '+_table+' set '+self._fields_id+'=null where id=%s', (act[1],))
elif act[0] == 4:
- # table of the field (parent_model in case of inherit)
- field = obj.pool[self._obj]._fields[self._fields_id]
- field_model = field.base_field.model_name
- field_table = obj.pool[field_model]._table
- cr.execute("select 1 from {0} where id=%s and {1}=%s".format(field_table, self._fields_id), (act[1], id))
- if not cr.fetchone():
+ # check whether the given record is already linked
+ rec = obj.browse(cr, SUPERUSER_ID, act[1], {'prefetch_fields': False})
+ if int(rec[self._fields_id]) != id:
# Must use write() to recompute parent_store structure if needed and check access rules
obj.write(cr, user, [act[1]], {self._fields_id:id}, context=context or {})
elif act[0] == 5: