On Sep 13, 2010, at 4:55 AM, mdipierro wrote: > > Can you help debug? In gluon/validators.py > > def __call__(self, value): > try: > v = decimal.Decimal(str(value)) # << line 725 > ... > except (ValueError, TypeError, decimal.InvalidOperation): > pass > return (value, self.error_message) > > why is the exception not caught?
Catching InvalidOperation was a fix we added a while back. So it's probably a version problem. BTW, I notice that decimal.py is not locale-sensitive. The regex it's using to parse the number has a literal period in it, so no hope of a comma being accepted, at least not in 2.6 and earlier (I have no idea about later). Massimo, I notice that there's no way to call IS_DECIMAL_IN_RANGE(None,None): that is, to ask for a decimal number without caring about min/max. That seems wrong to me. > > On Sep 13, 2:22 am, Kenneth <[email protected]> wrote: >> Hello, >> >> I have a tablefield defined as decimal(10,2). >> >> Fields for SQLFORM is defined as: >> fields=['price_consumer'] >> field_labels=['price_cunsumer': T('price consumer')] >> >> and then the form is generated as: >> form = SQLFORM(db.product, fields=fields, labels=field_labels) >> >> When I try to fill the form with values I get a Internal error because >> i tried to put the price with a comma, so 12,50 is not allowed but >> 12.50 is. >> >> How to indicate the problem and not to get the Internal error? >> >> Error traceback: >> Traceback (most recent call last): >> File "gluon/restricted.py", line 186, in restricted >> exec ccode in environment >> File "/data/domains/exp-kal.nudata.fi/applications/init/controllers/ >> product.py", line 99, in <module> >> File "gluon/globals.py", line 96, in <lambda> >> self._caller = lambda f: f() >> File "gluon/tools.py", line 2219, in f >> return action(*a, **b) >> File "/data/domains/exp-kal.nudata.fi/applications/init/controllers/ >> product.py", line 81, in edit >> if form.accepts(request.vars, session): >> File "gluon/sqlhtml.py", line 906, in accepts >> hideerror=hideerror, >> File "gluon/html.py", line 1512, in accepts >> status = self._traverse(status,hideerror) >> File "gluon/html.py", line 522, in _traverse >> newstatus = c._traverse(status,hideerror) and newstatus >> File "gluon/html.py", line 522, in _traverse >> newstatus = c._traverse(status,hideerror) and newstatus >> File "gluon/html.py", line 522, in _traverse >> newstatus = c._traverse(status,hideerror) and newstatus >> File "gluon/html.py", line 522, in _traverse >> newstatus = c._traverse(status,hideerror) and newstatus >> File "gluon/html.py", line 529, in _traverse >> newstatus = self._validate() >> File "gluon/html.py", line 1300, in _validate >> (value, errors) = validator(value) >> File "gluon/validators.py", line 2313, in __call__ >> return self.other(value) >> File "gluon/validators.py", line 725, in __call__ >> v = decimal.Decimal(str(value)) >> File "/usr/lib64/python2.5/decimal.py", line 614, in __new__ >> self._sign, self._int, self._exp = >> context._raise_error(ConversionSyntax) >> File "/usr/lib64/python2.5/decimal.py", line 2325, in _raise_error >> raise error, explanation >> InvalidOperation

