Opened 6 years ago

Closed 6 years ago

Last modified 4 years ago

#10513 closed (fixed)

Template filter "floatformat" does not support __float__ anymore.

Reported by: sebastian_noack Owned by: Alex
Component: Template system Version: 1.0
Severity: Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

Since django 1.0 the template filter floatformat, converts the value to unicode and after it to Decimal. So you can't pass anymore objects to floatformat, which provides a float method but not a unicode or str method.

Attachments (2)

floatfilter-__float__-regression.diff (1.1 KB) - added by steingrd 6 years ago.
support float objects with regression test
floatfilter.diff (2.5 KB) - added by Alex 6 years ago.

Download all attachments as: .zip

Change History (10)

comment:1 Changed 6 years ago by ikelly

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted

Changed 6 years ago by steingrd

support float objects with regression test

comment:2 Changed 6 years ago by steingrd

  • Has patch set

I've attached a patch with a regression test for objects with __float__ methods and a proposed fix. Objects with __float__ methods are simply converted to floats. It passes all the tests.

comment:3 Changed 6 years ago by ikelly

  • Patch needs improvement set

The problem with the patch is that decimal objects have a __float__ method. We don't want to convert decimals to floats due to the possible loss of precision, so the code should only convert to a float if it has already failed to convert to a decimal directly.

Changed 6 years ago by Alex

comment:4 Changed 6 years ago by Alex

  • milestone set to 1.1
  • Patch needs improvement unset

comment:5 Changed 6 years ago by Alex

  • Owner changed from nobody to Alex

comment:6 Changed 6 years ago by jacob

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

(In [10278]) Fixed #10513: floatformat now works with floatish things, not just real floats. Thanks, Alex.

comment:7 Changed 6 years ago by jacob

(In [10299]) [1.0.X] Fixed #10513: floatformat now works with floatish things, not just real floats. Thanks, Alex. Backport of [10278] from trunk.

comment:8 Changed 4 years ago by jacob

  • milestone 1.1 deleted

Milestone 1.1 deleted

Note: See TracTickets for help on using tickets.
Back to Top