yourlabs / django-autocomplete-light

A fresh approach to autocomplete implementations, specially for Django. Status: v4 alpha, v3 stable, v2 & v1 deprecated.
https://django-autocomplete-light.readthedocs.io
MIT License
1.79k stars 467 forks source link

Django 3.2 autocomplete_fields and DAL Conflicting #1258

Closed selected-pixel-jameson closed 2 years ago

selected-pixel-jameson commented 3 years ago

When I upgrade to Django 3.2 (works fine on Django 3.1) I'm running into the error described in the link below. https://code.djangoproject.com/ticket/32659?cversion=2&cnum_hist=2

I've come to find that this error is not being generated by a Django AutoComplete Light field however, It is being generated by autocomplete_fields = [field_name] in the Django Admin.

My best guess is that there is some kind of conflict with the Django 3.2 updates and the Select2.js script.

I have a need to be able to use both Djangos autocomplete_fields as well as custom DAL AutoComplete queries.

I currently have DAL 3.8.2 installed.

Any insight into this issue would be very helpful. Thank you.

Forbidden (Permission denied): /admin_x951pu/autocomplete/
Traceback (most recent call last):
  File "/Users/xxxxxxxxxxxx/.pyenv/versions/xxxxxxxxxxx/lib/python3.6/site-packages/django/utils/datastructures.py", line 76, in __getitem__
    list_ = super().__getitem__(key)
KeyError: 'app_label'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/xxxxxxxxxxxx/.pyenv/versions/xxxxxxxxxxx/lib/python3.6/site-packages/django/contrib/admin/views/autocomplete.py", line 61, in process_request
    app_label = request.GET['app_label']
  File "/Users/xxxxxxxxxxxx/.pyenv/versions/xxxxxxxxxxx/lib/python3.6/site-packages/django/utils/datastructures.py", line 78, in __getitem__
    raise MultiValueDictKeyError(key)
django.utils.datastructures.MultiValueDictKeyError: 'app_label'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/Users/xxxxxxxxxxxx/.pyenv/versions/xxxxxxxxxxx/lib/python3.6/site-packages/django/core/handlers/exception.py", line 47, in inner
    response = get_response(request)
  File "/Users/xxxxxxxxxxxx/.pyenv/versions/xxxxxxxxxxx/lib/python3.6/site-packages/django/core/handlers/base.py", line 181, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/Users/xxxxxxxxxxxx/.pyenv/versions/xxxxxxxxxxx/lib/python3.6/site-packages/django/contrib/admin/sites.py", line 250, in wrapper
    return self.admin_view(view, cacheable)(*args, **kwargs)
  File "/Users/xxxxxxxxxxxx/.pyenv/versions/xxxxxxxxxxx/lib/python3.6/site-packages/django/utils/decorators.py", line 130, in _wrapped_view
    response = view_func(request, *args, **kwargs)
  File "/Users/xxxxxxxxxxxx/.pyenv/versions/xxxxxxxxxxx/lib/python3.6/site-packages/django/views/decorators/cache.py", line 44, in _wrapped_view_func
    response = view_func(request, *args, **kwargs)
  File "/Users/xxxxxxxxxxxx/.pyenv/versions/xxxxxxxxxxx/lib/python3.6/site-packages/django/contrib/admin/sites.py", line 232, in inner
    return view(request, *args, **kwargs)
  File "/Users/xxxxxxxxxxxx/.pyenv/versions/xxxxxxxxxxx/lib/python3.6/site-packages/django/contrib/admin/sites.py", line 417, in autocomplete_view
    return AutocompleteJsonView.as_view(admin_site=self)(request)
  File "/Users/xxxxxxxxxxxx/.pyenv/versions/xxxxxxxxxxx/lib/python3.6/site-packages/django/views/generic/base.py", line 70, in view
    return self.dispatch(request, *args, **kwargs)
  File "/Users/xxxxxxxxxxxx/.pyenv/versions/xxxxxxxxxxx/lib/python3.6/site-packages/django/views/generic/base.py", line 98, in dispatch
    return handler(request, *args, **kwargs)
  File "/Users/xxxxxxxxxxxx/.pyenv/versions/xxxxxxxxxxx/lib/python3.6/site-packages/django/contrib/admin/views/autocomplete.py", line 20, in get
    self.term, self.model_admin, self.source_field, to_field_name = self.process_request(request)
  File "/Users/xxxxxxxxxxxx/.pyenv/versions/xxxxxxxxxxx/lib/python3.6/site-packages/django/contrib/admin/views/autocomplete.py", line 65, in process_request
    raise PermissionDenied from e
django.core.exceptions.PermissionDenied
Atorich commented 3 years ago

The same. DAL which is coming from django-taggit breaks django3.2 native autocomplete...

ruslan287 commented 3 years ago

+1 - Django-taggit > autocompleate-light > PermissionDesined

Atorich commented 3 years ago

BTW the issue is appearing only when taggit & native autocomplete are on the same page.

selected-pixel-jameson commented 3 years ago

@Atorich That is not the case for me. I don't have taggit on the page in question, but it is installed.

shalltell commented 2 years ago

This issue happens for me when I use DAL in conjunction with native django autocomplete. It's been fixed on this PR: https://github.com/yourlabs/django-autocomplete-light/issues/1239

It has been fixed in 3.9.0rc1 pip install https://github.com/yourlabs/django-autocomplete-light/archive/refs/tags/3.9.0rc1.tar.gz