Opened 2 years ago
Closed 2 years ago
#34191 closed Cleanup/optimization (duplicate)
ModelAdmin.search_fields fails for DecimalField and __exact
Reported by: | Klaas van Schelven | Owned by: | nobody |
---|---|---|---|
Component: | contrib.admin | Version: | 3.2 |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
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.']
Change History (1)
comment:1 by , 2 years ago
Component: | Uncategorized → contrib.admin |
---|---|
Resolution: | → duplicate |
Status: | new → closed |
Type: | Uncategorized → Cleanup/optimization |
Note:
See TracTickets
for help on using tickets.
Duplicate of #26001.