Opened 3 years ago

Closed 3 years ago

#18800 closed Bug (fixed)

Template cannot format integers bigger than maximum float

Reported by: jbvsmo@… Owned by: nobody
Component: Template system Version: 1.4
Severity: Normal Keywords: float, long
Cc: jason@…, bradpitcher@… Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no

Description

I cannot render in templates any integer (long in this case) bigger than the maximum float (approx. 3e308) because the django.utils.numberformat module do cast everything to float just to check the sign.

Funny thing is that the number is then converted to string and the minus symbol is removed. So, the easiest fix would be: Grab the sign after string formatting.

I made this change and generated a patch with my IDE (that's why the funky file path). All the tests pass.

Attachments (1)

local_history.patch (716 bytes) - added by jbvsmo@… 3 years ago.
Remove float call that can break on big integers

Download all attachments as: .zip

Change History (6)

Changed 3 years ago by jbvsmo@…

Remove float call that can break on big integers

comment:1 Changed 3 years ago by jwmayfield

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

I can confirm that passing in a number that's larger than sys.float_info.max does cause the django.utils.numberformat.format function to throw an exception. The patch needs to be updated with standard relative directory rather than the Windows-based directory that's on it now. Also needs a unit test.

comment:2 Changed 3 years ago by jwmayfield

  • Cc jason@… added

comment:3 Changed 3 years ago by bradpitcher

  • Owner changed from nobody to bradpitcher
  • Status changed from new to assigned

comment:4 Changed 3 years ago by bradpitcher

  • Cc bradpitcher@… added
  • Needs tests unset
  • Owner changed from bradpitcher to nobody
  • Patch needs improvement unset
  • Status changed from assigned to new

Pull request with tests here: https://github.com/django/django/pull/358

comment:5 Changed 3 years ago by Florian Apolloner <florian@…>

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

In 319e1355190d414ee1b095b26fbb494cf9a27578:

Fixed #18800 -- Support numbers bigger than max float in numberformat.

Thanks to jbvsmo for the patch and Brad Pitcher for the tests.

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