diff --git a/openerp/http.py b/openerp/http.py index e65ce3e1a6c..6ac8c23695d 100644 --- a/openerp/http.py +++ b/openerp/http.py @@ -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