From 291119c802af576a09cc1ac0eb479ea7f592b8f8 Mon Sep 17 00:00:00 2001 From: Christophe Simonis Date: Thu, 21 May 2015 12:49:36 +0200 Subject: [PATCH] [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. --- openerp/http.py | 6 ++++++ 1 file changed, 6 insertions(+) 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