Skip to content
Snippets Groups Projects
Commit 291119c8 authored by Christophe Simonis's avatar Christophe Simonis
Browse files

[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.
parent 6e54c8d1
No related branches found
No related tags found
No related merge requests found
......@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment