[Django] #30086: The numberformat template filter does not respect local localization settings

18 views
Skip to first unread message

Django

unread,
Jan 9, 2019, 5:00:34 AM1/9/19
to django-...@googlegroups.com
#30086: The numberformat template filter does not respect local localization
settings
-------------------------------------------+------------------------
Reporter: Meiyer | Owner: nobody
Type: Bug | Status: new
Component: Template system | Version: 1.11
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------------+------------------------
Specifically, when the filter is used within the `{% localize [on|off] %}`
block with the localization setting opposed to the value of `USE_L10N`
('on' when `USE_L10N = False` or 'off' when `USE_L10N = True`), the
localization setting has not effect.

This is due to the use of `formats.number_format()` without its `use_l10n`
parameter, by the `numberformat` template filter (e.g.
https://github.com/django/django/blob/master/django/template/defaultfilters.py#L144,
https://github.com/django/django/blob/master/django/template/defaultfilters.py#L163).
The value of the `use_l10n` parameter shall be taken out of the template
rendering context. But I do not see any easy solution to this, as filters
do not take context...

--
Ticket URL: <https://code.djangoproject.com/ticket/30086>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Jan 9, 2019, 11:10:56 AM1/9/19
to django-...@googlegroups.com
#30086: Document how floatformat template filter interacts with the localize
template tag
--------------------------------------+------------------------------------
Reporter: Meiyer | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: Documentation | Version: 1.11
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by Tim Graham):

* type: Bug => Cleanup/optimization
* component: Template system => Documentation
* stage: Unreviewed => Accepted


Old description:

> Specifically, when the filter is used within the `{% localize [on|off]
> %}` block with the localization setting opposed to the value of
> `USE_L10N` ('on' when `USE_L10N = False` or 'off' when `USE_L10N =
> True`), the localization setting has not effect.
>
> This is due to the use of `formats.number_format()` without its
> `use_l10n` parameter, by the `numberformat` template filter (e.g.
> https://github.com/django/django/blob/master/django/template/defaultfilters.py#L144,
> https://github.com/django/django/blob/master/django/template/defaultfilters.py#L163).
> The value of the `use_l10n` parameter shall be taken out of the template
> rendering context. But I do not see any easy solution to this, as filters
> do not take context...

New description:

Specifically, when the filter is used within the `{% localize [on|off] %}`
block with the localization setting opposed to the value of `USE_L10N`
('on' when `USE_L10N = False` or 'off' when `USE_L10N = True`), the
localization setting has not effect.

This is due to the use of `formats.number_format()` without its `use_l10n`
parameter, by the `numberformat` template filter (e.g.

https://github.com/django/django/blob/c2c85663e2dd06c9ed9c9ec2d02202d6d668d7f0/django/template/defaultfilters.py#L144,
https://github.com/django/django/blob/c2c85663e2dd06c9ed9c9ec2d02202d6d668d7f0/django/template/defaultfilters.py#L163).


The value of the `use_l10n` parameter shall be taken out of the template
rendering context. But I do not see any easy solution to this, as filters
do not take context...

--

Comment:

As long as the behavior doesn't contract existing documentation, perhaps
the solution is the document the current behavior.

--
Ticket URL: <https://code.djangoproject.com/ticket/30086#comment:1>

Django

unread,
Jan 20, 2019, 9:19:55 PM1/20/19
to django-...@googlegroups.com
#30086: Document how floatformat template filter interacts with the localize
template tag
--------------------------------------+------------------------------------
Reporter: Meiyer | Owner: nobody

Type: Cleanup/optimization | Status: new
Component: Documentation | Version: 1.11
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------

Comment (by Marc Parizeau):

Replying to [comment:1 Tim Graham]:


> As long as the behavior doesn't contract existing documentation, perhaps
the solution is the document the current behavior.

Documenting would be better than nothing, but this behavior goes against
the principle of least astonishment. Finding a way to honor the localize
directive would be better. Any other filters that are affected by this
limitation?

--
Ticket URL: <https://code.djangoproject.com/ticket/30086#comment:2>

Django

unread,
Jan 21, 2019, 3:48:41 AM1/21/19
to django-...@googlegroups.com
#30086: Document how floatformat template filter interacts with the localize
template tag
--------------------------------------+------------------------------------
Reporter: Meiyer | Owner: nobody

Type: Cleanup/optimization | Status: new
Component: Documentation | Version: 1.11
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------

Comment (by Claude Paroz):

All filters are affected. As the reporter noticed, the filters are
currently not aware of the rendering context. That's no easy fix.

--
Ticket URL: <https://code.djangoproject.com/ticket/30086#comment:3>

Django

unread,
Jan 21, 2019, 4:48:08 PM1/21/19
to django-...@googlegroups.com
#30086: Document how floatformat template filter interacts with the localize
template tag
--------------------------------------+------------------------------------
Reporter: Meiyer | Owner: nobody

Type: Cleanup/optimization | Status: new
Component: Documentation | Version: 1.11
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------

Comment (by Meiyer):

Replying to [comment:2 Marc Parizeau]:


> this behavior goes against the principle of least astonishment

+1
I consider this as a bug in the implementation of the filter, even though
the original title of the ticket was modified by Tim. Why would something
inside a `{% localize off %}` block still keep being localised?.. I
actually opened this ticket after having to dig through Django's code and
adding debug statements to understand what was happening.

Going forward, I see only two possible solutions:

* either introduce for filters a non-breaking support for context
(meaning, filters will be able to take context without breaking existing
code),
* or, deprecate the `floatformat` filter (and possibly other), replacing
it (them) with tags.

I personally favour the first option, but I realise it will require a lot
of effort.

--
Ticket URL: <https://code.djangoproject.com/ticket/30086#comment:4>

Django

unread,
Jan 21, 2019, 5:25:50 PM1/21/19
to django-...@googlegroups.com
#30086: Document how floatformat template filter interacts with the localize
template tag
--------------------------------------+------------------------------------
Reporter: Meiyer | Owner: nobody

Type: Cleanup/optimization | Status: new
Component: Documentation | Version: 1.11
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------

Comment (by Tim Graham):

In my 10 years of work with Django, I don't recall another report of this
issue, so I doubt that such disruptive changes would be acceptable for
what I perceive as a relatively minor issue. You're welcome to make your
proposal on the DevelopersMailingList to try to gather a consensus. A
custom `floatformat` template tag may meet your needs, but deprecating the
filter seems a bit drastic for the 99% of users who aren't affected by
this issue.

--
Ticket URL: <https://code.djangoproject.com/ticket/30086#comment:5>

Django

unread,
Jan 22, 2019, 4:50:44 AM1/22/19
to django-...@googlegroups.com
#30086: Document how floatformat template filter interacts with the localize
template tag
--------------------------------------+------------------------------------
Reporter: Meiyer | Owner: nobody

Type: Cleanup/optimization | Status: new
Component: Documentation | Version: 1.11
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------

Comment (by Claude Paroz):

Did someone explore adding support for
`@register.filter(takes_context=True)`. If someone can produce some proof-
of-concept code, it may have a chance to get accepted.

--
Ticket URL: <https://code.djangoproject.com/ticket/30086#comment:6>

Django

unread,
Nov 7, 2019, 2:40:17 PM11/7/19
to django-...@googlegroups.com
#30086: Document how floatformat template filter interacts with the localize
template tag
--------------------------------------+------------------------------------
Reporter: Meiyer | Owner: nobody

Type: Cleanup/optimization | Status: new
Component: Documentation | Version: 1.11
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by Florian Demmer):

* cc: Florian Demmer (added)


--
Ticket URL: <https://code.djangoproject.com/ticket/30086#comment:7>

Django

unread,
Oct 6, 2020, 11:00:00 AM10/6/20
to django-...@googlegroups.com
#30086: Document how floatformat template filter interacts with the localize
template tag
--------------------------------------+------------------------------------
Reporter: Meiyer | Owner: nobody

Type: Cleanup/optimization | Status: new
Component: Documentation | Version: 1.11
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by Carsten Fuchs):

* cc: Carsten Fuchs (added)


--
Ticket URL: <https://code.djangoproject.com/ticket/30086#comment:8>

Django

unread,
Jun 22, 2021, 6:08:37 AM6/22/21
to django-...@googlegroups.com
#30086: Document how floatformat template filter interacts with the localize
template tag
-------------------------------------+-------------------------------------
Reporter: Meiyer | Owner: nobody
Type: | Status: closed
Cleanup/optimization |
Component: Documentation | Version: 1.11
Severity: Normal | Resolution: duplicate

Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* status: new => closed
* resolution: => duplicate
* stage: Accepted => Unreviewed


Comment:

Closing as a duplicate of #32873 — which will remove the USE_L10N setting.

--
Ticket URL: <https://code.djangoproject.com/ticket/30086#comment:9>

Django

unread,
Jun 22, 2021, 8:31:35 AM6/22/21
to django-...@googlegroups.com
#30086: Document how floatformat template filter interacts with the localize
template tag
-------------------------------------+-------------------------------------
Reporter: Meiyer | Owner: nobody

Type: | Status: closed
Cleanup/optimization |
Component: Documentation | Version: 1.11
Severity: Normal | Resolution: duplicate
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Meiyer):

Mariusz, I do not see how Claude’s PR resolves the problem discussed in
this ticket. The `floatformat` builtin filter will still return a
localised result irrespective of the `{% localize off %}` tag. This is not
yet documented in
https://docs.djangoproject.com/en/3.2/ref/templates/builtins/#floatformat.

--
Ticket URL: <https://code.djangoproject.com/ticket/30086#comment:10>

Django

unread,
Jun 23, 2021, 2:35:23 AM6/23/21
to django-...@googlegroups.com
#30086: Document how floatformat template filter interacts with the localize
template tag
--------------------------------------+------------------------------------
Reporter: Meiyer | Owner: nobody
Type: Cleanup/optimization | Status: new

Component: Documentation | Version: 1.11
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by Mariusz Felisiak):

* status: closed => new
* resolution: duplicate =>


* stage: Unreviewed => Accepted


Comment:

Replying to [comment:10 Meiyer]:


> Mariusz, I do not see how Claude’s PR resolves the problem discussed in
this ticket. The `floatformat` builtin filter will still return a
localised result irrespective of the `{% localize off %}` tag. This is not
yet documented in
https://docs.djangoproject.com/en/3.2/ref/templates/builtins/#floatformat.

True, we can still document that `floatformat` ignores `{% localize on|off
%}`.

--
Ticket URL: <https://code.djangoproject.com/ticket/30086#comment:11>

Django

unread,
Sep 3, 2021, 3:26:49 AM9/3/21
to django-...@googlegroups.com
#30086: Document how floatformat template filter interacts with the localize
template tag
-------------------------------------+-------------------------------------
Reporter: Meiyer | Owner: Mariusz
Type: | Felisiak
Cleanup/optimization | Status: assigned

Component: Documentation | Version: 1.11
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* owner: nobody => Mariusz Felisiak
* status: new => assigned
* has_patch: 0 => 1


Comment:

[https://github.com/django/django/pull/14832 PR]

--
Ticket URL: <https://code.djangoproject.com/ticket/30086#comment:12>

Django

unread,
Sep 6, 2021, 3:06:43 AM9/6/21
to django-...@googlegroups.com
#30086: Make floatformat template filter independent of USE_L10N and allow forcing
unlocalized format.

-------------------------------------+-------------------------------------
Reporter: Meiyer | Owner: Mariusz
Type: | Felisiak
Cleanup/optimization | Status: assigned
Component: Template system | Version: 1.11
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* component: Documentation => Template system


--
Ticket URL: <https://code.djangoproject.com/ticket/30086#comment:13>

Django

unread,
Sep 7, 2021, 5:30:31 AM9/7/21
to django-...@googlegroups.com
#30086: Make floatformat template filter independent of USE_L10N and allow forcing
unlocalized format.
-------------------------------------+-------------------------------------
Reporter: Meiyer | Owner: Mariusz
Type: | Felisiak
Cleanup/optimization | Status: assigned
Component: Template system | Version: 1.11
Severity: Normal | Resolution:
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Carlton Gibson):

* stage: Accepted => Ready for checkin


--
Ticket URL: <https://code.djangoproject.com/ticket/30086#comment:14>

Django

unread,
Sep 8, 2021, 2:37:45 AM9/8/21
to django-...@googlegroups.com
#30086: Make floatformat template filter independent of USE_L10N and allow forcing
unlocalized format.
-------------------------------------+-------------------------------------
Reporter: Meiyer | Owner: Mariusz
Type: | Felisiak
Cleanup/optimization | Status: closed

Component: Template system | Version: 1.11
Severity: Normal | Resolution: fixed

Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by GitHub <noreply@…>):

* status: assigned => closed
* resolution: => fixed


Comment:

In [changeset:"4a43335d300da942602fbf216cd0a53b60827ab4" 4a43335d]:
{{{
#!CommitTicketReference repository=""
revision="4a43335d300da942602fbf216cd0a53b60827ab4"
Fixed #30086, Refs #32873 -- Made floatformat template filter independent
of USE_L10N.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/30086#comment:15>

Reply all
Reply to author
Forward
0 new messages