Opened 4 years ago

Closed 10 months ago

Last modified 10 months ago

#14807 closed Uncategorized (fixed)

django.utils.formats localize_input inserts thousands_separator into boolean values

Reported by: vanschelven 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 vanschelven 4 years ago.
patch.2 (1.5 KB) - added by vanschelven 4 years ago.

Download all attachments as: .zip

Change History (12)

Changed 4 years ago by vanschelven

comment:1 Changed 4 years ago by jezdez

  • Component changed from Uncategorized to Internationalization
  • milestone set to 1.3
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted

Changed 4 years ago by vanschelven

comment:2 Changed 4 years ago by vanschelven

  • 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 4 years ago by jezdez

  • Triage Stage changed from Accepted to Ready for checkin

Needs to be backported, too.

comment:4 Changed 4 years ago by russellm

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

(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 4 years ago by russellm

(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 3 years ago by jacob

  • milestone 1.3 deleted

Milestone 1.3 deleted

comment:7 follow-up: Changed 10 months ago by klaas@…

  • Easy pickings unset
  • Resolution fixed deleted
  • Severity set to Normal
  • Status changed from closed to new
  • Type set to 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 10 months ago by timo

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

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 10 months ago by vanschelven

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

comment:10 Changed 10 months ago by timo

Please do it, thank-you.

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