Code

Opened 2 years ago

Closed 2 years ago

#17779 closed Bug (invalid)

floatformat template filter no longer works at all

Reported by: jasper@… Owned by: nobody
Component: Template system Version: master
Severity: Release blocker Keywords: floatformat templatetag
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no

Description

As of a recent commit, the floatformat template filter no longer works at all:

>>> from django.template.defaultfilters import floatformat
>>> import decimal
>>> floatformat(decimal.Decimal('12.345'), 2)
u'12.345'
>>> floatformat(12.345, 2)
u'12.345'
>>> floatformat(12.345, 5)
u'12.345'
>>> floatformat(12.345, -2)
u'12.345'

Attachments (0)

Change History (2)

comment:1 Changed 2 years ago by jasper@…

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

The input value is simply returned due to this exception occurring when floatformat tries to quantize the Decimal instance:

Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/Users/.../django/template/defaultfilters.py", line 177, in floatformat
    Context(prec=prec)).as_tuple()
  File "/usr/local/Cellar/python/2.7.2/lib/python2.7/decimal.py", line 2442, in quantize
    'quantize result has too many digits for current context')
  File "/usr/local/Cellar/python/2.7.2/lib/python2.7/decimal.py", line 3844, in _raise_error
    raise error(explanation)
InvalidOperation: quantize result has too many digits for current context

This exception is caught at the end of the floatformat function and input_val is returned.

comment:2 Changed 2 years ago by jasper@…

  • Resolution set to invalid
  • Status changed from new to closed

I traced the problem to a build of Python that was incapable of doing proper math with the Decimal class; the bug is not in Django. Apologies for the noise.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.