#17414 closed Bug (fixed)
intcomma raises ZeroDivisionError for locales whose NUMBER_GROUPING is unspecified
Reported by: | jittat | Owned by: | nobody |
---|---|---|---|
Component: | Internationalization | Version: | dev |
Severity: | Normal | Keywords: | ZeroDivisionError, intcomma |
Cc: | Triage Stage: | Accepted | |
Has patch: | no | Needs documentation: | no |
Needs tests: | yes | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
When using locales that do not specify NUMBER_GROUPING
(like 'fa','ja','th',) template filter intcomma
(from humanize) raises ZeroDivisionError.
Version: Django 1.4 pre-alpha SVN-17202
How to reproduce:
- Make sure that
USE_L10N = True
insettings.py
- Try this code in shell
from django.utils import translation translation.activate('th') t = "{% load humanize %}}{{ 100|intcomma }}" from django.template import Template, Context Template(t).render(Context())
- You can change 'th' to 'ja', 'mn', 'ro' and many others.
Possible cause:
This is not the issue directly related to contrib.humanize's intcomma
.
The exception occurs in function format
in django.utils.numberformat
when Django tries to divide something with parameter grouping
. This parameter is assigned in function number_format
in django.utils.formats
from a call to get_format('NUMBER_GROUPING')
, which returns 0
for many locales (e.g., th, ja, km, zh) with no definition of NUMBER_GROUPING
in the format files. Therefore, you get ZeroDivisionError
.
How to fix:
I am not sure where to put the fixing code. These are the options:
- Use something like 3 as a default for
NUMBER_GROUPING
. - Change function
format
indjango.utils.numberformat
to make sure thatgrouping
is non-zero (and if it is zero, use something like 3 as a default).
Since I am not sure where to put the fix, I have not tried to produce the patch. I can try to do that for the 2nd option if it makes sense.
Attachments (1)
Change History (4)
comment:1 by , 13 years ago
Needs tests: | set |
---|---|
Triage Stage: | Unreviewed → Accepted |
comment:2 by , 13 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
In [17267]: