[FIX] http: `request.env` and request.cr` now raise `RuntimeError`.

These method used to raise an `AttributeError` when `self.registry`
returns `None`. Now raises a more appropriated exception.
This commit is contained in:
Christophe Simonis 2015-05-21 12:49:36 +02:00
parent 6e54c8d17a
commit 291119c802
1 changed files with 6 additions and 0 deletions

View File

@ -201,7 +201,11 @@ class WebRequest(object):
def env(self):
"""
The :class:`~openerp.api.Environment` bound to current request.
Raises a :class:`RuntimeError` if the current requests is not bound
to a database.
"""
if not self.db:
return RuntimeError('request not bound to a database')
return openerp.api.Environment(self.cr, self.uid, self.context)
@lazy_property
@ -236,6 +240,8 @@ class WebRequest(object):
"""
# can not be a lazy_property because manual rollback in _call_function
# if already set (?)
if not self.db:
return RuntimeError('request not bound to a database')
if not self._cr:
self._cr = self.registry.cursor()
return self._cr