leplatrem/django-sizefield

Problem with values 1 Pb or greater

mjpritchard opened this issue · 3 comments

Storing a value greater than or equal to 1 Pb / 1024.0 TB causes IndexError (list index out of range) when rendered using the templatetag in either admin or user template.
/site-packages/sizefield/utils.py in filesizeformat, line 51
Using version 0.5 on django 1.6.5

More info:

from sizefield.utils import filesizeformat
filesizeformat(1125899906800000,1)
u'1024.0TB'
filesizeformat(1125899906900000,1)
Traceback (most recent call last):
File "", line 1, in
File "/Users/mjp43/Virtualenvs/jasmindb/lib/python2.7/site-packages/sizefield/utils.py", line 51, in filesizeformat
value = filesize_number_format(bytes / units_list[len_unints_list][1])
IndexError: list index out of range

Yes indeed : https://github.com/leplatrem/django-sizefield/blob/master/sizefield/utils.py#L21

If you want to add some more units, or add a fix to grab the last unit instead when the limit is reached, feel free to open a pull request !

Fixed in 0.7