Opened 3 years ago

Closed 3 years ago

Last modified 3 years ago

#19348 closed Cleanup/optimization (fixed)

Sizes returned by filesizeformat are incorrect.

Reported by: george_edison Owned by: claudep
Component: Documentation Version: 1.4
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no

Description

The template filter 'filesizeformat' appears to be returning incorrect results:

>>> from django.template.defaultfilters import filesizeformat
>>> filesizeformat(123456789)
u'117.7 MB'

According to the International System of Units (SI), the prefix "mega-" indicates a quantity of exactly 1000000. Django appears to be using 1024*1024 (1048576) to represent a megabyte which corresponds with the SI prefix "mebi-".

This error can be corrected in one of two ways:

  • Replace the units in the strings returned with their proper equivalents:
    KB => KiB
    MB => MiB
    etc.
    
  • Use the correct values for KB, MB, etc.:
    1024    => 1000
    1048576 => 1000000
    etc.
    

Change History (6)

comment:1 Changed 3 years ago by russellm

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Resolution set to wontfix
  • Status changed from new to closed

Duplicate of #8733, and I haven't seen any significant change in the way the world views the SI prefixes since that ticket was closed wontfix.

comment:2 Changed 3 years ago by claudep

  • Component changed from Template system to Documentation
  • Resolution wontfix deleted
  • Status changed from closed to reopened
  • Triage Stage changed from Unreviewed to Accepted
  • Type changed from Bug to Cleanup/optimization

I can buy the rationale of #8733, but this should be documented.

comment:3 Changed 3 years ago by claudep

  • Owner changed from nobody to claudep
  • Status changed from reopened to new

comment:4 Changed 3 years ago by claudep

Here's the text I suggest to add to the filesizeformat filter documentation. This should be revised/adapted by a native English speaker.

.. admonition:: File sizes and SI units

    Strictly speaking, ``filesizeformat`` does not conform to the International
    System of Units, which recommends to use KiB, MiB, GiB,... when byte sizes
    are calculated in powers of 1024 (which is the case here). Instead, Django
    has chosen to keep using traditional unit names (KB, MB, GB,...)
    corresponding to the more widespread usage.

comment:5 Changed 3 years ago by Tim Graham <timograham@…>

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

In 63e6cd1bb3edccb4db1eb6a79153fa31d2114cd4:

Fixed #19348 - Clarified the units of filesizeformat.

Thanks george_edison for the report and Claude Paroz for the patch.

comment:6 Changed 3 years ago by Tim Graham <timograham@…>

In c90156fc188200795a24c24b9ea97eef32356e55:

[1.5.X] Fixed #19348 - Clarified the units of filesizeformat.

Thanks george_edison for the report and Claude Paroz for the patch.

Backport of 63e6cd1bb3 from master

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