[Django] #29816: Bug fix for ticket #29138

6 views
Skip to first unread message

Django

unread,
Oct 2, 2018, 11:35:08 AM10/2/18
to django-...@googlegroups.com
#29816: Bug fix for ticket #29138
-------------------------------------+-------------------------------------
Reporter: | Owner: nobody
ConstantinoSchillebeeckx |
Type: Bug | Status: new
Component: | Version: 2.1
contrib.admin |
Severity: Normal | Keywords: autocomplete_fields
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
I've put together a
[https://github.com/ConstantinoSchillebeeckx/django/tree/fix-29138 bug
fix] for the case when `autocomplete_fields` is used on a foreign-key
field that has `on_fields` specified; bug originally reported
[https://code.djangoproject.com/ticket/29138 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
}}}

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

Django

unread,
Oct 2, 2018, 12:33:43 PM10/2/18
to django-...@googlegroups.com
#29816: Bug fix for ticket #29138
-------------------------------------+-------------------------------------
Reporter: Constantino | Owner: nobody

Schillebeeckx |
Type: Bug | Status: new
Component: contrib.admin | Version: 2.1
Severity: Normal | Resolution:
Keywords: autocomplete_fields | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Description changed by Constantino Schillebeeckx:

Old description:

New description:

I've put together a
[https://github.com/ConstantinoSchillebeeckx/django/tree/fix-29138 bug
fix] for the case when `autocomplete_fields` is used on a foreign-key
field that has `on_fields` specified; bug originally reported
[https://code.djangoproject.com/ticket/29138 here].

'''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.

--

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

Django

unread,
Oct 2, 2018, 1:14:48 PM10/2/18
to django-...@googlegroups.com
#29816: Bug fix for ticket #29138
-------------------------------------+-------------------------------------
Reporter: Constantino | Owner: nobody
Schillebeeckx |
Type: Bug | Status: closed
Component: contrib.admin | Version: 2.1
Severity: Normal | Resolution: duplicate

Keywords: autocomplete_fields | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham):

* status: new => closed
* resolution: => duplicate


Comment:

Please leave a comment on #29138 rather than open a new ticket.

--
Ticket URL: <https://code.djangoproject.com/ticket/29816#comment:2>

Reply all
Reply to author
Forward
0 new messages