Replacing a partner column with an unstored function field makes OpenERP crash at module upgrade

Bug #1253200 reported by Stefan Rijnhart (Opener)
24
This bug affects 5 people
Affects Status Importance Assigned to Milestone
Odoo Server (MOVED TO GITHUB)
New
Undecided
Unassigned

Bug Description

What I'm trying to do
-----------------------------
Very simple use case here: replacing the 'street' field on the partner model by separate fields for street name and house number. We want to make 'street' a function field that returns a concatenation of both, for compatibility with the rest of the system. Storing such a field has a performance impact, and is unnecessary for our purposes.

What goes wrong
------------------------
This is all working as expected, until I update any module except 'base' (or 'all'). This gives the following error:

2013-11-20 18:29:09,913 20442 DEBUG dbname openerp.modules.loading: module base: loading objects
2013-11-20 18:29:10,599 20442 ERROR dbname openerp.sql_db: Programming error: column res_partner.street does not exist
LINE 1: ...s_partner."use_parent_address",res_partner."date",res_partne...
                                                             ^
, in query SELECT res_partner."comment",res_partner."ean13",res_partner."color",res_partner."use_parent_address",res_partner."date",res_partner."street",res_partner."city",res_partner."user_id",res_partner."
zip",res_partner."title",res_partner."country_id",res_partner."website",res_partner."parent_id",res_partner."supplier",res_partner."type",res_partner."email",res_partner."vat",res_partner."function",res_part
ner."customer",res_partner."fax",res_partner."street2",res_partner."employee",res_partner."tz",res_partner."lang",res_partner."credit_limit",res_partner."name",res_partner."phone",res_partner."mobile",res_pa
rtner."ref",res_partner."birthdate",res_partner."is_company",res_partner."state_id",res_partner.id FROM "res_partner" WHERE res_partner.id IN %s ORDER BY name
2013-11-20 18:29:10,599 20442 DEBUG dbname openerp.tools.translate: translation went wrong for "'Install'", skipped
2013-11-20 18:29:10,599 20442 ERROR dbname openerp.sql_db: bad query: SELECT res_users."menu_id",res_users."login_date",res_users."company_id",res_users."signature",res_users."active",res_users."login",r
es_users."password",res_users."partner_id",res_users."id",res_users."action_id",res_users."company_id",res_users."active",res_users."partner_id",res_users.id FROM "res_users" WHERE res_users.id IN (1) ORDER
BY id

Here is the relevant part of the backtrace:

  /path/to/openobject-server/openerp/modules/loading.py(326)load_modules()
-> modobj.button_upgrade(cr, SUPERUSER_ID, ids)
  /path/to/openobject-server/openerp/addons/base/module/module.py(544)button_upgrade()
-> self.button_install(cr, uid, to_install, context=context)
  /path/to/openobject-server/openerp/addons/base/module/module.py(414)button_install()
-> return dict(ACTION_DICT, name=_('Install'))
  /path/to/openobject-server/openerp/tools/translate.py(225)__call__()
-> lang = self._get_lang(frame)
  /path/to/openobject-server/openerp/tools/translate.py(211)_get_lang()
-> lang = pool.get('res.users').context_get(cr, uid)['lang']
  /path/to/openobject-server/openerp/tools/cache.py(18)lookup()
-> r = self.lookup(self2, cr, *args)
  /path/to/openobject-server/openerp/tools/cache.py(46)lookup()
-> value = d[key] = self.method(self2, cr, *args)
  /path/to/openobject-server/openerp/addons/base/res/res_users.py(363)context_get()

Analysis:
-----------
Very early in the upgrade process, fetching a translation triggers res_users::context_get(). This does a browse on the user, which also fetches all the partner fields as res.users inherits from res.partner in 7.0. The custom module that changes the 'street' field not having been loaded yet, OpenERP thinks it is the database column from the res_partner table. This causes a crash because the column does not exist (OpenERP proactively drops columns that have been turned into unstored function or related fields).

Proposed solution:
--------------------------
Don't browse, but perform a read on the relevant fields. This limits the impact of the matter to only those fields.

Related branches

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Duplicates of this bug

Other bug subscribers

Remote bug watches

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