[IMP] ir.model.data: get_object() never raises an exception when check=False
bzr revid: rco@openerp.com-20140123103306-tilma2dahgfsm70t
This commit is contained in:
parent
5b0ff455c5
commit
d68bb48e44
|
@ -29,7 +29,7 @@ import openerp.modules.registry
|
||||||
from openerp import SUPERUSER_ID
|
from openerp import SUPERUSER_ID
|
||||||
from openerp import tools
|
from openerp import tools
|
||||||
from openerp.osv import fields,osv
|
from openerp.osv import fields,osv
|
||||||
from openerp.osv.orm import Model
|
from openerp.osv.orm import Model, browse_null
|
||||||
from openerp.tools.safe_eval import safe_eval as eval
|
from openerp.tools.safe_eval import safe_eval as eval
|
||||||
from openerp.tools import config
|
from openerp.tools import config
|
||||||
from openerp.tools.translate import _
|
from openerp.tools.translate import _
|
||||||
|
@ -884,18 +884,26 @@ class ir_model_data(osv.osv):
|
||||||
raise ValueError('Not enough access rights on the external ID: %s.%s' % (module, xml_id))
|
raise ValueError('Not enough access rights on the external ID: %s.%s' % (module, xml_id))
|
||||||
return model, False
|
return model, False
|
||||||
|
|
||||||
def get_object(self, cr, uid, module, xml_id, context=None, check_existence_and_raise=True):
|
def get_object(self, cr, uid, module, xml_id, context=None, check=True):
|
||||||
""" Returns a browsable record for the given module name and xml_id or
|
""" Returns a browsable record for the given module name and xml_id.
|
||||||
raise ValueError if not found
|
If not found, raise a ValueError or return a browse_null, depending
|
||||||
|
on the value of `check`.
|
||||||
|
|
||||||
:param boolean check_existence_and_raise: v7 compatibility mode, check
|
:param check: when true, check whether record exists and raise a
|
||||||
existence and raise if not found
|
ValueError if it does not; otherwise return a browse_null or
|
||||||
|
non-existing record.
|
||||||
"""
|
"""
|
||||||
res_model, res_id = self.get_object_reference(cr, uid, module, xml_id)
|
try:
|
||||||
result = self.pool[res_model].browse(cr, uid, res_id, context=context)
|
res_model, res_id = self.get_object_reference(cr, uid, module, xml_id)
|
||||||
if check_existence_and_raise and not result.exists():
|
record = self.pool[res_model].browse(cr, uid, res_id, context=context)
|
||||||
|
except ValueError:
|
||||||
|
if check:
|
||||||
|
raise
|
||||||
|
return browse_null()
|
||||||
|
|
||||||
|
if check and not record.exists():
|
||||||
raise ValueError('No record found for unique ID %s.%s. It may have been deleted.' % (module, xml_id))
|
raise ValueError('No record found for unique ID %s.%s. It may have been deleted.' % (module, xml_id))
|
||||||
return result
|
return record
|
||||||
|
|
||||||
def _update_dummy(self,cr, uid, model, module, xml_id=False, store=True):
|
def _update_dummy(self,cr, uid, model, module, xml_id=False, store=True):
|
||||||
if not xml_id:
|
if not xml_id:
|
||||||
|
|
|
@ -685,10 +685,7 @@ class groups_view(osv.osv):
|
||||||
# and introduces the reified group fields
|
# and introduces the reified group fields
|
||||||
# we have to try-catch this, because at first init the view does not exist
|
# we have to try-catch this, because at first init the view does not exist
|
||||||
# but we are already creating some basic groups
|
# but we are already creating some basic groups
|
||||||
try:
|
view = self.pool['ir.model.data'].get_object(cr, SUPERUSER_ID, 'base', 'user_groups_view', context=context, check=False)
|
||||||
view = self.pool['ir.model.data'].get_object(cr, SUPERUSER_ID, 'base', 'user_groups_view', context=context, check_existence_and_raise=False)
|
|
||||||
except ValueError:
|
|
||||||
view = False
|
|
||||||
if view and view.exists() and view._table_name == 'ir.ui.view':
|
if view and view.exists() and view._table_name == 'ir.ui.view':
|
||||||
xml1, xml2 = [], []
|
xml1, xml2 = [], []
|
||||||
xml1.append(E.separator(string=_('Application'), colspan="4"))
|
xml1.append(E.separator(string=_('Application'), colspan="4"))
|
||||||
|
|
Loading…
Reference in New Issue