From f90b29b9382b8865a055f72432a85b2837642d7c Mon Sep 17 00:00:00 2001 From: Olivier Dony Date: Fri, 25 Jul 2014 16:33:48 +0200 Subject: [PATCH] [FIX] res.users: safer read() when computing default company value The goal is to avoid any kind of prefetching of other fields when copmuting the default company, as this will sometimes happen in the middle of a database update, when the default company is used for setting the default value of new columns. In that case the db schema may not fully match the in-memory model, leading to an SQL error. --- openerp/addons/base/res/res_users.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/openerp/addons/base/res/res_users.py b/openerp/addons/base/res/res_users.py index a864725a9cc..f1ddf4f1b42 100644 --- a/openerp/addons/base/res/res_users.py +++ b/openerp/addons/base/res/res_users.py @@ -226,11 +226,14 @@ class res_users(osv.osv): def _get_company(self,cr, uid, context=None, uid2=False): if not uid2: uid2 = uid - # use read method to compute default values to don't create browse record and fetch all fields - # browse crash for install or update module - user = self.pool['res.users'].read(cr, uid, uid2, ['company_id'], context) - company_id = user['company_id'] and user['company_id'][0] or False - return company_id + # Use read() to compute default company, and pass load=_classic_write to + # avoid useless name_get() calls. This will avoid prefetching fields + # while computing default values for new db columns, as the + # db backend may not be fully initialized yet. + user_data = self.pool['res.users'].read(cr, uid, uid2, ['company_id'], + context=context, load='_classic_write') + comp_id = user_data['company_id'] + return comp_id or False def _get_companies(self, cr, uid, context=None): c = self._get_company(cr, uid, context)