[7.0][trunk] Reference field and module dependency

Bug #1260372 reported by Yann Papouin
12
This bug affects 2 people
Affects Status Importance Assigned to Milestone
OpenUpgrade Server
New
Undecided
Unassigned

Bug Description

I'm stuck on something really hard.
I experienced this bug while upgrading from 6.1 to 7.0 and the error occurred when upgrading "crm.lead" partners.
A call write is done via model.write(cr, SUPERUSER_ID, row[0], {partner_field: row[1]}).

Since the "crm.lead" model own some stored fields ('day_open, 'day_close', 'state'), their values are computed on write and I don't know why, but all fields are "get" in _store_set_values.

The problem here is that two references fields exists in the "crm.lead" module:
- 'ref': fields.reference('Reference', selection=crm._links_get, size=128),
- 'ref2': fields.reference('Reference 2', selection=crm._links_get, size=128),

A reference field can be a "sale.order" and that's the problem since "sale.order" is not loaded when upgrading the crm module (and sale is not a dependency of crm), so the obj return by pool.get is None in __getitem__ [orm.py:468]:

elif field_column._type == 'reference':
    if result_line[field_name]:
        if isinstance(result_line[field_name], browse_record):
            new_data[field_name] = result_line[field_name]
        else:
            ref_obj, ref_id = result_line[field_name].split(',')
            ref_id = long(ref_id)
            if ref_id:
                obj = self._table.pool.get(ref_obj)
                new_data[field_name] = browse_record(...)
            else:
                new_data[field_name] = browse_null()
    else:
        new_data[field_name] = browse_null()

It will produced this error:

  File "/openerp/osv/orm.py", line 340, in __init__
    self._table_name = self._table._name
AttributeError: 'NoneType' object has no attribute '_name'

description: updated
Revision history for this message
Yann Papouin (yann-papouin) wrote :

Not so hard in fact, I just added a new condition on obj and the upgrade worked fine. I'm reporting this as a bug for OpenERP server as it could occurred in other situations

  if obj:
      new_data[field_name] = browse_record(...)
  else:
      new_data[field_name] = browse_null()

summary: - Reference field and module dependency
+ [7.0][trunk] Reference field and module dependency
Revision history for this message
Yann Papouin (yann-papouin) wrote :

OpenUpgrade is built upon ocb-server or openobject-server to know if a merge proposal into ocb-server is needed since a fix for official 7.0 is highly unlikely ?

Revision history for this message
Stefan Rijnhart (Opener) (stefan-opener) wrote :

OpenUpgrade is built upon official branches.

Good to hear you already solved it. You might have tried to add the following stanza to the openupgrade-server config file:

[openupgrade]
forced_deps = {'crm': ['sale']}

This should force sale to be loaded before crm is.

Revision history for this message
Stefan Rijnhart (Opener) (stefan-opener) wrote :

BTW maybe a patch on OpenUpgrade-server is sufficient? Please explicitely mention OpenUpgrade and the problem that it solves in a comment above the change, because we have to port these changes with every new major release.

no longer affects: openupgrade-addons
no longer affects: openobject-server
Revision history for this message
Rolf Wojtech (rolf-wojtech) wrote :

Could you elaborate why this bug should not affect openupgrade-addons and/or openobject-server?

I am using the latest version for a migration and ran into this issue. How was this fixed?

Revision history for this message
Rolf Wojtech (rolf-wojtech) wrote :

Never mind, i misread the last status update.
Anyways I am currently facing this issue and could test potential fixes.

Revision history for this message
Stefan Rijnhart (Opener) (stefan-opener) wrote :

Did you try the suggested (untested) workaround?

Revision history for this message
Rolf Wojtech (rolf-wojtech) wrote :

I am not sure if you are refering to the workaround #1 by Yann Papouin (yann-papouin) or #3 by Stefan Rijnhart?

What worked for me was a combination of #3 (adding the following to openerp-server.conf):
[openupgrade]
 forced_deps = {'crm': ['sale']}

and adding sale as a dependency to crm in __openerp__.py as seen in the attached patch.

I had tried forced_deps only first and it did not work. Later I tried it with the patch but without forced_deps and it seems to work as well.

I will check it out once I have cleared a few other roadblock but I wanted to leave this comment nonetheless in case I forget about it again ;)

Revision history for this message
Rolf Wojtech (rolf-wojtech) wrote :

Forgot the attachment to my previous post.

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.