[Django] #34191: ModelAdmin.search_fields fails for DecimalField and __exact

5 views
Skip to first unread message

Django

unread,
Nov 30, 2022, 4:36:40 AM11/30/22
to django-...@googlegroups.com
#34191: ModelAdmin.search_fields fails for DecimalField and __exact
----------------------------------------------+------------------------
Reporter: Klaas van Schelven | Owner: nobody
Type: Uncategorized | Status: new
Component: Uncategorized | Version: 3.2
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 |
----------------------------------------------+------------------------
From the docs:

> If you don’t want to use icontains as the lookup, you can use any lookup
by appending it the field. For example, you could use exact by setting
search_fields to ['first_name__exact']

However, when I do this for any DecimalField, and enter any non-parsable
(as a Decimal) value in the search box, I get the following:


{{{
Internal Server Error: /admin/valuta/redacted/
Traceback (most recent call last):
File "..../lib/python3.10/site-
packages/django/db/models/fields/__init__.py", line 1552, in to_python
return decimal.Decimal(value)
decimal.InvalidOperation: [<class 'decimal.ConversionSyntax'>]

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "..../lib/python3.10/site-
packages/django/core/handlers/exception.py", line 47, in inner
response = get_response(request)
File "..../lib/python3.10/site-packages/django/core/handlers/base.py",
line 181, in _get_response
response = wrapped_callback(request, *callback_args,
**callback_kwargs)
File "..../lib/python3.10/site-
packages/django/contrib/admin/options.py", line 616, in wrapper
return self.admin_site.admin_view(view)(*args, **kwargs)
File "..../lib/python3.10/site-packages/django/utils/decorators.py",
line 130, in _wrapped_view
response = view_func(request, *args, **kwargs)
File "..../lib/python3.10/site-
packages/django/views/decorators/cache.py", line 44, in _wrapped_view_func
response = view_func(request, *args, **kwargs)
File "..../lib/python3.10/site-packages/django/contrib/admin/sites.py",
line 232, in inner
return view(request, *args, **kwargs)
File "..../lib/python3.10/site-packages/django/utils/decorators.py",
line 43, in _wrapper
return bound_method(*args, **kwargs)
File "..../lib/python3.10/site-packages/django/utils/decorators.py",
line 130, in _wrapped_view
response = view_func(request, *args, **kwargs)
File "..../lib/python3.10/site-
packages/django/contrib/admin/options.py", line 1697, in changelist_view
cl = self.get_changelist_instance(request)
File "..../lib/python3.10/site-
packages/django/contrib/admin/options.py", line 736, in
get_changelist_instance
return ChangeList(
File "..../lib/python3.10/site-
packages/django/contrib/admin/views/main.py", line 99, in __init__
self.queryset = self.get_queryset(request)
File "..../lib/python3.10/site-
packages/django/contrib/admin/views/main.py", line 476, in get_queryset
qs, search_may_have_duplicates = self.model_admin.get_search_results(
File "..../lib/python3.10/site-
packages/django/contrib/admin/options.py", line 1032, in
get_search_results
queryset = queryset.filter(reduce(operator.or_, or_queries))
File "..../lib/python3.10/site-packages/django/db/models/query.py", line
941, in filter
return self._filter_or_exclude(False, args, kwargs)
File "..../lib/python3.10/site-packages/django/db/models/query.py", line
961, in _filter_or_exclude
clone._filter_or_exclude_inplace(negate, args, kwargs)
File "..../lib/python3.10/site-packages/django/db/models/query.py", line
968, in _filter_or_exclude_inplace
self._query.add_q(Q(*args, **kwargs))
File "..../lib/python3.10/site-packages/django/db/models/sql/query.py",
line 1416, in add_q
clause, _ = self._add_q(q_object, self.used_aliases)
File "..../lib/python3.10/site-packages/django/db/models/sql/query.py",
line 1435, in _add_q
child_clause, needed_inner = self.build_filter(
File "..../lib/python3.10/site-packages/django/db/models/sql/query.py",
line 1288, in build_filter
return self._add_q(
File "..../lib/python3.10/site-packages/django/db/models/sql/query.py",
line 1435, in _add_q
child_clause, needed_inner = self.build_filter(
File "..../lib/python3.10/site-packages/django/db/models/sql/query.py",
line 1370, in build_filter
condition = self.build_lookup(lookups, col, value)
File "..../lib/python3.10/site-packages/django/db/models/sql/query.py",
line 1216, in build_lookup
lookup = lookup_class(lhs, rhs)
File "..../lib/python3.10/site-packages/django/db/models/lookups.py",
line 25, in __init__
self.rhs = self.get_prep_lookup()
File "..../lib/python3.10/site-packages/django/db/models/lookups.py",
line 77, in get_prep_lookup
return self.lhs.output_field.get_prep_value(self.rhs)
File "..../lib/python3.10/site-
packages/django/db/models/fields/__init__.py", line 1565, in
get_prep_value
return self.to_python(value)
File "..../lib/python3.10/site-
packages/django/db/models/fields/__init__.py", line 1554, in to_python
raise exceptions.ValidationError(
django.core.exceptions.ValidationError: ['‘adf’ value must be a decimal
number.']

}}}

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

Django

unread,
Nov 30, 2022, 5:06:45 AM11/30/22
to django-...@googlegroups.com
#34191: ModelAdmin.search_fields fails for DecimalField and __exact
-------------------------------------+-------------------------------------

Reporter: Klaas van Schelven | Owner: nobody
Type: | Status: closed
Cleanup/optimization |
Component: contrib.admin | Version: 3.2
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
* component: Uncategorized => contrib.admin
* type: Uncategorized => Cleanup/optimization


Comment:

Duplicate of #26001.

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

Reply all
Reply to author
Forward
0 new messages