Opened 7 years ago
Last modified 7 years ago
#29816 closed Bug
Bug fix for ticket #29138 — at Initial Version
| Reported by: | Constantino Schillebeeckx | Owned by: | nobody |
|---|---|---|---|
| Component: | contrib.admin | Version: | 2.1 |
| Severity: | Normal | Keywords: | autocomplete_fields |
| Cc: | Triage Stage: | Unreviewed | |
| Has patch: | no | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
I've put together a bug fix for the case when autocomplete_fields is used on a foreign-key field that has on_fields specified; bug originally reported here.
Note I've been able to update the current unit tests to work with my new code; however one of the new unit tests doesn't pass. The error is a bit beyond my knowledge of how Django works and I would appreciate some help in fixing it:
======================================================================
ERROR: test_success (admin_views.test_autocomplete_view.AutocompleteJsonViewTests)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/usr/local/opt/pyenv/versions/3.6.3/lib/python3.6/unittest/case.py", line 59, in testPartExecutor
yield
File "/usr/local/opt/pyenv/versions/3.6.3/lib/python3.6/unittest/case.py", line 605, in run
testMethod()
File "/Users/constantino/Desktop/django/tests/admin_views/test_autocomplete_view.py", line 72, in test_success
response = AutocompleteJsonView.as_view(**self.as_view_args_to_field)(request)
File "/Users/constantino/Desktop/django/django/views/generic/base.py", line 68, in view
return self.dispatch(request, *args, **kwargs)
File "/Users/constantino/Desktop/django/django/views/generic/base.py", line 88, in dispatch
return handler(request, *args, **kwargs)
File "/Users/constantino/Desktop/django/django/contrib/admin/views/autocomplete.py", line 31, in get
self.object_list = self.get_queryset()
File "/Users/constantino/Desktop/django/django/contrib/admin/views/autocomplete.py", line 48, in get_queryset
qs, search_use_distinct = self.model_admin.get_search_results(self.request, qs, self.term)
File "/Users/constantino/Desktop/django/django/contrib/admin/options.py", line 1026, in get_search_results
queryset = queryset.filter(reduce(operator.or_, or_queries))
File "/Users/constantino/Desktop/django/django/db/models/query.py", line 844, in filter
return self._filter_or_exclude(False, *args, **kwargs)
File "/Users/constantino/Desktop/django/django/db/models/query.py", line 862, in _filter_or_exclude
clone.query.add_q(Q(*args, **kwargs))
File "/Users/constantino/Desktop/django/django/db/models/sql/query.py", line 1263, in add_q
clause, _ = self._add_q(q_object, self.used_aliases)
File "/Users/constantino/Desktop/django/django/db/models/sql/query.py", line 1281, in _add_q
current_negated, allow_joins, split_subq)
File "/Users/constantino/Desktop/django/django/db/models/sql/query.py", line 1287, in _add_q
split_subq=split_subq,
File "/Users/constantino/Desktop/django/django/db/models/sql/query.py", line 1225, in build_filter
condition = self.build_lookup(lookups, col, value)
File "/Users/constantino/Desktop/django/django/db/models/sql/query.py", line 1087, in build_lookup
raise FieldError('Related Field got invalid lookup: {}'.format(lookup_name))
django.core.exceptions.FieldError: Related Field got invalid lookup: icontains
Note:
See TracTickets
for help on using tickets.