openerp-india team mailing list archive
-
openerp-india team
-
Mailing list archive
-
Message #04927
[Bug 915975] [NEW] Fields.related writes to the target model with source id
Public bug reported:
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
** Affects: openobject-server
Importance: Undecided
Status: New
--
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:
New
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
Follow ups
-
[Bug 915975] Re: Data corruption: fields.related writes to the target model with source id
From: Lara (Therp), 2013-01-23
-
[Bug 915975] Re: Data corruption: fields.related writes to the target model with source id
From: Lara Freeke (Therp), 2013-01-23
-
[Bug 915975] Re: Data corruption: fields.related writes to the target model with source id
From: Stefan Rijnhart (Therp), 2012-11-16
-
[Bug 915975] Re: Data corruption: fields.related writes to the target model with source id
From: Jignesh Rathod(OpenERP), 2012-11-06
-
[Bug 915975] Re: Data corruption: fields.related writes to the target model with source id
From: Serpent Consulting Services, 2012-10-20
-
[Bug 915975] Re: Data corruption: fields.related writes to the target model with source id
From: Stefan Rijnhart (Therp), 2012-10-20
-
[Bug 915975] Re: Data corruption: fields.related writes to the target model with source id
From: Stefan Rijnhart (Therp), 2012-10-20
-
[Bug 915975] Re: Data corruption: fields.related writes to the target model with source id
From: Launchpad Bug Tracker, 2012-10-20
-
[Bug 915975] Re: Fields.related writes to the target model with source id
From: Stefan Rijnhart (Therp), 2012-10-20
-
[Bug 915975] Re: Fields.related writes to the target model with source id
From: Launchpad Bug Tracker, 2012-10-20
-
[Bug 915975] Re: Fields.related writes to the target model with source id
From: Jignesh Rathod(OpenERP), 2012-04-12
-
[Bug 915975] Re: Fields.related writes to the target model with source id
From: Jignesh Rathod(OpenERP), 2012-04-12
-
[Bug 915975] Re: Fields.related writes to the target model with source id
From: Stefan Rijnhart (Therp), 2012-03-14
-
[Bug 915975] Re: Fields.related writes to the target model with source id
From: Stefan Rijnhart (Therp), 2012-03-03
-
[Bug 915975] Re: Fields.related writes to the target model with source id
From: Stefan Rijnhart (Therp), 2012-03-03
-
[Bug 915975] Re: Fields.related writes to the target model with source id
From: Jignesh Rathod(OpenERP), 2012-03-02
-
[Bug 915975] Re: Fields.related writes to the target model with source id
From: Jignesh Rathod(OpenERP), 2012-03-02
-
[Bug 915975] [NEW] Fields.related writes to the target model with source id
From: Stefan Rijnhart (Therp), 2012-01-13
References