← Back to team overview

openerp-india team mailing list archive

[Bug 915975] Re: Fields.related writes to the target model with source id

 

Hi Jignesh,

thank you for your attention on this issue!

The fields that you demonstrate are regular many2many fields. The
problem does not occur in that case. The problem only occurs with
fields.related of type 'many2many'. I have created a module that
demonstrates the problem, and I will attach a video with spoken word to
talk you through the problem.

You can get the module here to see for yourself:

http://bazaar.launchpad.net/~stefan-therp/junk/lp915975-fields-related-
many2many/files

Cheers,
Stefan.


** Attachment added: "Demonstration video"
   https://bugs.launchpad.net/openobject-server/+bug/915975/+attachment/2806108/+files/out-2.ogv

-- 
You received this bug notification because you are a member of OpenERP
Indian Team, which is subscribed to OpenERP Server.
https://bugs.launchpad.net/bugs/915975

Title:
  Fields.related writes to the target model with source id

Status in OpenERP Server:
  Incomplete

Bug description:
  Hi,

  Problem:
  ------------
  A fields.related with type='many2many' tries to write to the target model but with id of the source model in case the original value of the many2many field on the target resource is empty.

  Analysis:
  -----------
  Take for example a column definition in osv class 'source.model':

    'related_field_id': fields.related('target_model_id',
  'target_field', type='many2many'),

  A value is written to this field. The current value on the target
  model is empty.

  The method related._fnct_write()[1] from osv/fields.py loops over
  ('target_model_id', 'target_field'). The second iteration is supposed
  to retrieve the resource id of the target model. It does so by setting
  't_id' to t_data['id'] in three different places (!) in the loop,
  where 't_data' is the browse object of the target resource. It still
  fails to do so in the circumstances described above.

  Although the code is a bit difficult to read, you can check that *if*
  the current value of the field (t_data[self.arg[i]])[2] is empty *and*
  type is in ('one2many', 'many2one')[3], t_id does not get set to
  t_data['id'] but keeps its original value instead. This original value
  is the resource id of the source model set in the first iteration of
  the loop.

  Result:
  ---------
  If a resource exists with this id, the new value get silently written to this wrong resource. If such a resource does not exist, the following error occurs: "'One of the records you are trying to modify has already been deleted".

  This problem occurs on openerp-server/6.0 (rev. 3565). Trunk has not
  been tested, but the function in which the problem occurs has remained
  unchanged.

  [1] http://bazaar.launchpad.net/~openerp/openobject-server/6.0/view/head:/bin/osv/fields.py?start_revid=3566#L863
  [2] http://bazaar.launchpad.net/~openerp/openobject-server/6.0/view/head:/bin/osv/fields.py?start_revid=3566#L874
  [3] http://bazaar.launchpad.net/~openerp/openobject-server/6.0/view/head:/bin/osv/fields.py?start_revid=3566#L875

To manage notifications about this bug go to:
https://bugs.launchpad.net/openobject-server/+bug/915975/+subscriptions


References