Opened 2 years ago

Closed 2 years ago

#28730 closed Bug (fixed)

Large integer literals lose precision in templates

Reported by: Fraser Nevett Owned by: nobody
Component: Template system Version: master
Severity: Normal Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


While looking at #28721, I realised that there is loss of precision on large integer literals:

>>> from django.template import Template, Context
>>> Template('{{ 999999999999999999999999999 }}').render(Context())

This happens because the code tries to first convert literal values to a float and then from the float to an int, which is a lossy operation.

Change History (5)

comment:1 Changed 2 years ago by Fraser Nevett

Type: UncategorizedBug

comment:2 Changed 2 years ago by Tim Graham

Triage Stage: UnreviewedAccepted

comment:3 Changed 2 years ago by Claude Paroz

Has patch: set
Version: 1.11master

comment:4 Changed 2 years ago by Tim Graham

Triage Stage: AcceptedReady for checkin

comment:5 Changed 2 years ago by Claude Paroz <claude@…>

Resolution: fixed
Status: newclosed

In 9ec7d8e:

Fixed #28730 -- Fixed loss of precision for large integer literals in templates

Thanks Fraser Nevett for the report and Tim Graham for patch edits.

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