Opened 6 years ago

Closed 3 years ago

Last modified 10 months ago

#14807 closed Uncategorized (fixed)

django.utils.formats localize_input inserts thousands_separator into boolean values

Reported by: Klaas van Schelven Owned by: nobody
Component: Internationalization Version: 1.2
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

Description

formats.localize_input(True)

I'm working in an environment where I've localized all my forms (set localize=True on all fields). I also have the USE_THOUSAND_SEPARATOR = True.

This results the value attr in my booleanfield to be set to "T,rue" (Dutch) or "T.rue" (US).

The ultimate culprit is django.utils.formats localize_input

There is a check there like so:

    if isinstance(value, (decimal.Decimal, float, int, long)):

which evaluates to True for Booleans (because booleans are ints, see "issubclass(bool, int)")

I do not currently have the time to provide tests etc. I do have a simple patch

Attachments (2)

patch (679 bytes) - added by Klaas van Schelven 6 years ago.
patch.2 (1.5 KB) - added by Klaas van Schelven 6 years ago.

Download all attachments as: .zip

Change History (13)

Changed 6 years ago by Klaas van Schelven

Attachment: patch added

comment:1 Changed 6 years ago by Jannis Leidel

Component: UncategorizedInternationalization
milestone: 1.3
Triage Stage: UnreviewedAccepted

Changed 6 years ago by Klaas van Schelven

Attachment: patch.2 added

comment:2 Changed 6 years ago by Klaas van Schelven

  • Added a patch, including a test this time. And still returning unicode for booleans (just not broken unicode)
  • Turns out the problem also surfaces in more general settings (i.e. just printing booleans on screen).

comment:3 Changed 6 years ago by Jannis Leidel

Triage Stage: AcceptedReady for checkin

Needs to be backported, too.

comment:4 Changed 6 years ago by Russell Keith-Magee

Resolution: fixed
Status: newclosed

(In [14804]) Fixed #14807 -- Ensure that boolean values aren't localized as T.rue and Fa.lse because of the thousand separator. Thanks to vanschelven for the report and patch.

comment:5 Changed 6 years ago by Russell Keith-Magee

(In [14807]) [1.2.X] Fixed #14807 -- Ensure that boolean values aren't localized as T.rue and Fa.lse because of the thousand separator. Thanks to vanschelven for the report and

Backport of r14804 from trunk.

comment:6 Changed 5 years ago by Jacob

milestone: 1.3

Milestone 1.3 deleted

comment:7 Changed 3 years ago by klaas@…

Easy pickings: unset
Resolution: fixed
Severity: Normal
Status: closednew
Type: Uncategorized
UI/UX: unset

When fixing this, input_localize was missed. My proposed solution (which is unfortunately not formatted as a pull request, nor does it have tests) is here:

https://github.com/vanschelven/django/commit/f0e39c83ec9174b8e5241caa6ba59b8e2e6deb66

Also copying my notes from that solution to justify reopening the issue:

6c53a81 only fixed localize(), but not localize_input()
It appears to me that this was simply an oversight at the time.

It seems that a new call-order for fields somewhere between Django 1.4
and Django 1.6 triggers triggers this bug again, but this time on the inputs
and only when rendering fields as_hidden.

comment:8 Changed 3 years ago by Tim Graham

Resolution: fixed
Status: newclosed

I'll be better to open a new ticket rather than reopening one that's three years old where the original fix has already been released, thanks.

comment:9 in reply to:  7 Changed 3 years ago by Klaas van Schelven

So was the new ticket created? Or am I expected to do this?

comment:10 Changed 3 years ago by Tim Graham

Please do it, thank-you.

comment:11 Changed 10 months ago by Tim Graham

The follow up ticket is #26173.

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