Revert "[FIX] fields: `digits()` computation"

This reverts commit eeedd2d9f5.

This revision introduces an issue more serious than the ones
it fixes. This is no longer possible to receive an email
aimed a sale.order thread with catchall.

To reproduce the issue:
 - Create a new sale order
 - Send a message in the thread to the customer
 - Reply to the mail received in the customer mailbox
 - Traceback, AttributeError: digits

 opw-640370
This commit is contained in:
Denis Ledoux 2015-05-20 19:13:04 +02:00
parent 7d69759e73
commit 49cb46fb78
2 changed files with 7 additions and 20 deletions

View File

@ -1054,8 +1054,7 @@ class Float(Field):
@property @property
def digits(self): def digits(self):
if callable(self._digits): if callable(self._digits):
with fields._get_cursor() as cr: return self._digits(fields.get_cursor())
return self._digits(cr)
else: else:
return self._digits return self._digits

View File

@ -43,7 +43,6 @@ import pytz
import re import re
import xmlrpclib import xmlrpclib
from operator import itemgetter from operator import itemgetter
from contextlib import contextmanager
from psycopg2 import Binary from psycopg2 import Binary
import openerp import openerp
@ -53,22 +52,13 @@ from openerp.tools import float_repr, float_round, frozendict, html_sanitize
import simplejson import simplejson
from openerp import SUPERUSER_ID, registry from openerp import SUPERUSER_ID, registry
@contextmanager def get_cursor():
def _get_cursor(): # retrieve a valid cursor from any environment
# yield a valid cursor from any environment or create a new one if none found
from openerp.api import Environment from openerp.api import Environment
from openerp.http import request
try:
request.env # force request's env to be computed
except RuntimeError:
pass # ignore if not in a request
for env in Environment.envs: for env in Environment.envs:
if not env.cr.closed: if not env.cr.closed:
yield env.cr return env.cr
break raise RuntimeError("No valid cursor found")
else:
with registry().cursor() as cr:
yield cr
EMPTY_DICT = frozendict() EMPTY_DICT = frozendict()
@ -406,8 +396,7 @@ class float(_column):
@property @property
def digits(self): def digits(self):
if self._digits_compute: if self._digits_compute:
with _get_cursor() as cr: return self._digits_compute(get_cursor())
return self._digits_compute(cr)
else: else:
return self._digits return self._digits
@ -1327,8 +1316,7 @@ class function(_column):
@property @property
def digits(self): def digits(self):
if self._digits_compute: if self._digits_compute:
with _get_cursor() as cr: return self._digits_compute(get_cursor())
return self._digits_compute(cr)
else: else:
return self._digits return self._digits