Opened 6 years ago

Closed 6 years ago

Last modified 6 years ago

#29578 closed Bug (fixed)

Django 2.1b and 2.1rc1 put thousand separator in _selected_action field containing id

Reported by: Sassan Haradji Owned by: Claude Paroz
Component: contrib.admin Version: 2.1
Severity: Release blocker 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

In django 2.1b and 2.1rc1 when I select an item with id 1600 in item list in django admin and try to delete the item, when I confirm the deletion django raises this error:

...
  File "/opt/escape/lib/python3.5/site-packages/django/contrib/admin/sites.py", line 223, in inner
    return view(request, *args, **kwargs)
  File "/opt/escape/lib/python3.5/site-packages/django/utils/decorators.py", line 45, in _wrapper
    return bound_method(*args, **kwargs)
  File "/opt/escape/lib/python3.5/site-packages/django/utils/decorators.py", line 142, in _wrapped_view
    response = view_func(request, *args, **kwargs)
  File "/opt/escape/lib/python3.5/site-packages/django/contrib/admin/options.py", line 1727, in changelist_view
    response = self.response_action(request, queryset=cl.get_queryset(request))
  File "/opt/escape/lib/python3.5/site-packages/django/contrib/admin/options.py", line 1409, in response_action
    queryset = queryset.filter(pk__in=selected)
  File "/opt/escape/lib/python3.5/site-packages/django/db/models/query.py", line 841, in filter
    return self._filter_or_exclude(False, *args, **kwargs)
  File "/opt/escape/lib/python3.5/site-packages/django/db/models/query.py", line 859, in _filter_or_exclude
    clone.query.add_q(Q(*args, **kwargs))
  File "/opt/escape/lib/python3.5/site-packages/django/db/models/sql/query.py", line 1263, in add_q
    clause, _ = self._add_q(q_object, self.used_aliases)
  File "/opt/escape/lib/python3.5/site-packages/django/db/models/sql/query.py", line 1287, in _add_q
    split_subq=split_subq,
  File "/opt/escape/lib/python3.5/site-packages/django/db/models/sql/query.py", line 1225, in build_filter
    condition = self.build_lookup(lookups, col, value)
  File "/opt/escape/lib/python3.5/site-packages/django/db/models/sql/query.py", line 1096, in build_lookup
    lookup = lookup_class(lhs, rhs)
  File "/opt/escape/lib/python3.5/site-packages/django/db/models/lookups.py", line 20, in __init__
    self.rhs = self.get_prep_lookup()
  File "/opt/escape/lib/python3.5/site-packages/django/db/models/lookups.py", line 210, in get_prep_lookup
    rhs_value = self.lhs.output_field.get_prep_value(rhs_value)
  File "/opt/escape/lib/python3.5/site-packages/django/db/models/fields/__init__.py", line 965, in get_prep_value
    return int(value)
ValueError: invalid literal for int() with base 10: '1٫600'

The character ٫ is my persian thousand separator.

Change History (10)

comment:1 by Carlton Gibson, 6 years ago

Hi Sassan,

Thanks for the report.

Could you possibly try to bisect the error to see where it was introduced or create a test case or minimal project demonstrating this so that we can do so?

comment:2 by Sassan Haradji, 6 years ago

While I'd love to help with the bisect unfortunately I have zero free time these days. It should happen for you if you have these lines in your settings:

LANGUAGE_CODE = 'fa'
locale.setlocale(locale.LC_ALL, 'fa_IR')
LANGUAGES = (
    ('fa', 'Farsi'),
)
USE_I18N = True
USE_L10N = True
USE_THOUSAND_SEPARATOR = True
THOUSAND_SEPARATOR = '٫'
NUMBER_GROUPING = 3

And you're using django 2.1rc1 and you try to remvoe an object with id >=1000 in django admin list.
It should be the minimal requirements to reproduce the issue but I doubt it has anything to do with persian langauge and it should happen in other locales too.
If you weren't able to reproduce the issue just tell me here and I'll try to find some time to do the bisect.

comment:3 by Carlton Gibson, 6 years ago

Triage Stage: UnreviewedAccepted

OK. I can reproduce. Bisected to 1b7780ea0802116eeef80b398a0432ac3f0ba9ef.

Thanks!

comment:5 by Claude Paroz, 6 years ago

Owner: changed from nobody to Claude Paroz
Status: newassigned

OK, the key to reproduce is to set NUMBER_GROUPING. My findings is that the faulty commit just revealed another bug in numberformat.format() not honoring forced l10n usage.

comment:6 by Claude Paroz, 6 years ago

Has patch: set

comment:7 by Tim Graham, 6 years ago

Triage Stage: AcceptedReady for checkin

comment:8 by Tim Graham <timograham@…>, 6 years ago

Resolution: fixed
Status: assignedclosed

In 0adfba96:

Fixed #29578 -- Made numberformat.format() honor forced l10n usage.

Thanks Sassan Haradji for the report.

comment:9 by Sassan Haradji, 6 years ago

Great, thanks.

comment:10 by Tim Graham <timograham@…>, 6 years ago

In 1084bcc4:

[2.1.x] Fixed #29578 -- Made numberformat.format() honor forced l10n usage.

Thanks Sassan Haradji for the report.
Backport of 0adfba968e28cfb4e4d681e658866debbbd68089 from master

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