← Back to team overview

openerp-india team mailing list archive

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

 

Hello Stefan ,

Yes,You are right , I have seen some inconsistancy in this situation.

Let me explain:
---------------------------


We have created M2M related field with type "M2M".

When I have added a record in releted field then its removed which is 
the first inconstancy(See which shows in video).

I have added record in regular "M2M" field then it is affact (attached) on related field
which is correct.

Now I have removed this record from related field, then same record is also 
removed from the regular field,So again I said it also inconsistant behaviour.

Lets compare this behaviour M2O field,

I have checked this same behaviour in 6.0(M2O relation on Hr_employee object)
and removed the readonly="1" from parent_id field.Now you can see manager field is related 
with department when I am changing the department ,Manager will change and 
If I remove the manager from there, Department will as it is.One more thing is I change manager 
field is does't affect to the department field.

>From this behaviour M2O is working fine and for M2M related field have inconsitant 
behaviour,That's why I am confirming this issue also I have attached video which is describe 
the problem more clearly.


Thanks for understanding!

** Changed in: openobject-server
   Importance: Undecided => Low

** Changed in: openobject-server
       Status: New => Confirmed

** Changed in: openobject-server
     Assignee: (unassigned) => OpenERP's Framework R&D (openerp-dev-framework)

-- 
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:
  Confirmed

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