#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 , 7 years ago
comment:2 by , 7 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 , 7 years ago
| Triage Stage: | Unreviewed → Accepted |
|---|
OK. I can reproduce. Bisected to 1b7780ea0802116eeef80b398a0432ac3f0ba9ef.
Thanks!
comment:4 by , 7 years ago
Weird, as the behavior is tested in https://github.com/django/django/blob/1ed8527e3df930ae54ef237e77f1a53faa0ff5ed/tests/admin_views/test_actions.py#L76
comment:5 by , 7 years ago
| Owner: | changed from to |
|---|---|
| Status: | new → assigned |
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:7 by , 7 years ago
| Triage Stage: | Accepted → Ready for checkin |
|---|
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?