Duplicating an _inherits'ed record may link translations to a wrong record or fails with an AccessError

Bug #1237878 reported by Guewen Baconnier @ Camptocamp
24
This bug affects 5 people
Affects Status Importance Assigned to Milestone
Odoo Server (MOVED TO GITHUB)
Fix Released
Low
OpenERP Publisher's Warranty Team

Bug Description

Hi,

Concerns:

  Duplication of records which are '_inherits' of another model as a product.product.
  Does not happen on a database where the IDs of the product.product are synchronized with the IDs of the product.template, so it is probably not reproducible on most of the databases, but as soon as you can have several variants for a template, it will happen.

Steps to reproduce:

  I don't know how we can reproduce it on runbot, as we need to have several variants for 1 template.
  However, the steps to reproduce it are just to create some templates, and several variants on each of them, then to duplicate a variant.

Actual behavior:

  Either the translations are linked with a wrong product.template, either the copy fails with the following error:

    AccessError
    One of the records you are trying to modify has already been deleted (Document type: Product Template).

    Moreover, the source values of a wrong product.template may be replaced by the one of the duplicated product.

    Probably related to: https://bugs.launchpad.net/openobject-server/+bug/410073

Expected:

  It duplicates the product with error with the correct translations.

My analysis:

  Say that we are copying the product with the ID 77. This product is related to a template whose ID is 25.

  The new ID of the copied product is 78. The new ID of the copied template is 26.

  The field name we are translating is 'name'

  In copy_translations() at http://bazaar.launchpad.net/~openerp/openobject-server/7.0/view/5095/openerp/osv/orm.py#L4970
  looking at the lines 5001-5002:

        elif field_name in self._inherit_fields:
            trans_name = self._inherit_fields[field_name][0] + "," + field_name

  Here, the translation name will be: 'product.template,name'
  Just below, on the line 5012:

        record['res_id'] = new_id

  We can already smell the issue: new_id is 78 and the translation is related to 'product.template'. Here, 'res_id' should likely be 26.

  Now, there is a direct consequence, when the translation is written, we end up in ir_translation._set_src http://bazaar.launchpad.net/~openerp/openobject-server/7.0/view/head:/openerp/addons/base/ir/ir_translation.py#L180:

    def _set_src(self, cr, uid, id, name, value, args, context=None):
        ''' When changing source term of a translation, change its value in db for
        the associated object, and the src field
        '''
        if context is None:
            context = {}
        record = self.browse(cr, uid, id, context=context)
        if value and record.type == 'model':
            model_name, field = record.name.split(',')
            model = self.pool.get(model_name)
            #We need to take the context without the language information, because we want to write on the
            #value store in db and not on the one associate with current language.
            #Also not removing lang from context trigger an error when lang is different
            context_wo_lang = context.copy()
            context_wo_lang.pop('lang', None)
            model.write(cr, uid, record.res_id, {field: value}, context=context_wo_lang)
        return self.write(cr, uid, id, {'src': value}, context=context)

  On this specific line:

            model.write(cr, uid, record.res_id, {field: value}, context=context_wo_lang)

  model is 'product.template'
  record.res_id is 78
  field is 'name'

  The result is the following:
      - if a template exists with the ID 78, the values will be written on this one.
      - if a template with ID 78 does not exist, we'll have an AccessError.

Tags: maintenance

Related branches

summary: - Duplicating an _inherits'ed record may copy random translations or fails
- with an AccessError
+ Duplicating an _inherits'ed record may link translations on a wrong
+ record or fails with an AccessError
summary: - Duplicating an _inherits'ed record may link translations on a wrong
+ Duplicating an _inherits'ed record may link translations to a wrong
record or fails with an AccessError
Changed in openobject-server:
assignee: nobody → OpenERP Publisher's Warranty Team (openerp-opw)
tags: added: maintenance
Revision history for this message
Guewen Baconnier @ Camptocamp (gbaconnier-c2c) wrote :

Here is a dump to reproduce the steps.

Branches:

    server: 5109 / launchpad_translations_on_behalf_of_openerp-20131026062452-54qhvc3cru0x8e6h
    addons: 9546 / launchpad_translations_on_behalf_of_openerp-20131028054233-15znliqv2eh2jq0i
    web: 4047 / launchpad_translations_on_behalf_of_openerp-20131027061322-op6b5ohzf6eiyiu2
    You will also need to put the module 'product_variant_simple' that I'll attach to this bug report in the addons-path. This module adds the actions for the variant views.

What I already did on the dump:
 - installed a fresh database with modules: product_variant_simple, sale
 - created some product.product on an existing product.template (15" LCD Monitor) so the IDs are not aligned between product.template and product.product

Steps to reproduce:
 1. Load the dump
 2. Open the menu "Sales / Products / Products"
 3. Select a product, for instance "USB Adapter"
 4. Use the duplicate function

Result:

  AccessError

  One of the records you are trying to modify has already been deleted (Document type: Product Template).

Revision history for this message
Guewen Baconnier @ Camptocamp (gbaconnier-c2c) wrote :
Changed in openobject-server:
status: New → Confirmed
importance: Undecided → Low
Revision history for this message
Martin Trigaux (OpenERP) (mat-openerp) wrote :

Hello,

Thanks for the report. Indeed there was an issue with the duplication of records with translated values from _inherits.
This was fixed in the server 7.0

revno: 5118 [merge]
revision-id: <email address hidden>

Regars

Changed in openobject-server:
status: Confirmed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.