3 | | '''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: |
4 | | |
5 | | {{{ |
6 | | ====================================================================== |
7 | | ERROR: test_success (admin_views.test_autocomplete_view.AutocompleteJsonViewTests) |
8 | | ---------------------------------------------------------------------- |
9 | | Traceback (most recent call last): |
10 | | File "/usr/local/opt/pyenv/versions/3.6.3/lib/python3.6/unittest/case.py", line 59, in testPartExecutor |
11 | | yield |
12 | | File "/usr/local/opt/pyenv/versions/3.6.3/lib/python3.6/unittest/case.py", line 605, in run |
13 | | testMethod() |
14 | | File "/Users/constantino/Desktop/django/tests/admin_views/test_autocomplete_view.py", line 72, in test_success |
15 | | response = AutocompleteJsonView.as_view(**self.as_view_args_to_field)(request) |
16 | | File "/Users/constantino/Desktop/django/django/views/generic/base.py", line 68, in view |
17 | | return self.dispatch(request, *args, **kwargs) |
18 | | File "/Users/constantino/Desktop/django/django/views/generic/base.py", line 88, in dispatch |
19 | | return handler(request, *args, **kwargs) |
20 | | File "/Users/constantino/Desktop/django/django/contrib/admin/views/autocomplete.py", line 31, in get |
21 | | self.object_list = self.get_queryset() |
22 | | File "/Users/constantino/Desktop/django/django/contrib/admin/views/autocomplete.py", line 48, in get_queryset |
23 | | qs, search_use_distinct = self.model_admin.get_search_results(self.request, qs, self.term) |
24 | | File "/Users/constantino/Desktop/django/django/contrib/admin/options.py", line 1026, in get_search_results |
25 | | queryset = queryset.filter(reduce(operator.or_, or_queries)) |
26 | | File "/Users/constantino/Desktop/django/django/db/models/query.py", line 844, in filter |
27 | | return self._filter_or_exclude(False, *args, **kwargs) |
28 | | File "/Users/constantino/Desktop/django/django/db/models/query.py", line 862, in _filter_or_exclude |
29 | | clone.query.add_q(Q(*args, **kwargs)) |
30 | | File "/Users/constantino/Desktop/django/django/db/models/sql/query.py", line 1263, in add_q |
31 | | clause, _ = self._add_q(q_object, self.used_aliases) |
32 | | File "/Users/constantino/Desktop/django/django/db/models/sql/query.py", line 1281, in _add_q |
33 | | current_negated, allow_joins, split_subq) |
34 | | File "/Users/constantino/Desktop/django/django/db/models/sql/query.py", line 1287, in _add_q |
35 | | split_subq=split_subq, |
36 | | File "/Users/constantino/Desktop/django/django/db/models/sql/query.py", line 1225, in build_filter |
37 | | condition = self.build_lookup(lookups, col, value) |
38 | | File "/Users/constantino/Desktop/django/django/db/models/sql/query.py", line 1087, in build_lookup |
39 | | raise FieldError('Related Field got invalid lookup: {}'.format(lookup_name)) |
40 | | django.core.exceptions.FieldError: Related Field got invalid lookup: icontains |
41 | | }}} |
| 3 | '''Note''' I've been able to update all unit tests and create some new ones, however the original ticket mentions using `to_field_allowed` to prevent data leaks. I've tried to implement it (see [https://github.com/ConstantinoSchillebeeckx/django/blob/fix-29138/django/contrib/admin/views/autocomplete.py#L29 here]), however I can't get it to play nicely with the unit tests. When uncommented, the `id_field` isn't properly being considered as to_field_allowed. I'm not familiar with this function, so could use some help troubleshooting. |