Opened 3 years ago

Closed 3 years ago

Last modified 3 years ago

#33261 closed Bug (duplicate)

Autocomplete field triggers a PermissionDenied error

Reported by: Gianluca Romanin 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

I added to my code a autocomplete field in the ModelAdmin class of a model name UserData
Code is pretty simple:

@admin.register(UserData)
class UserDataAdmin(admin.ModelAdmin):
    list_display = ("fiscal_code", "company", "surname", "name")
    fields = ["company", "name", "surname", "fiscal_code", "address", "identity_document"]
    # FIXME: autocomplete does not work in Django 3.2.X. Downgraded to 3.1.X
    autocomplete_fields = ["company"]

The interface shows "The results could not be loaded" and console shows the following errors:

Traceback (most recent call last):
  File "C:\Users\username\AppData\Local\pypoetry\Cache\virtualenvs\kdocweb-1PRTDUa5-py3.9\lib\site-packages\django\contrib\admin\views\autocomplete.py", line 61, in process_request
    app_label = request.GET['app_label']
  File "C:\Users\username\AppData\Local\pypoetry\Cache\virtualenvs\kdocweb-1PRTDUa5-py3.9\lib\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 "C:\Users\username\AppData\Local\pypoetry\Cache\virtualenvs\kdocweb-1PRTDUa5-py3.9\lib\site-packages\django\core\handlers\exception.py", line 47, in inner
    response = get_response(request)
  File "C:\Users\username\AppData\Local\pypoetry\Cache\virtualenvs\kdocweb-1PRTDUa5-py3.9\lib\site-packages\django\core\handlers\base.py", line 181, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "C:\Users\username\AppData\Local\pypoetry\Cache\virtualenvs\kdocweb-1PRTDUa5-py3.9\lib\site-packages\django\contrib\admin\sites.py", line 250, in wrapper
    return self.admin_view(view, cacheable)(*args, **kwargs)
  File "C:\Users\username\AppData\Local\pypoetry\Cache\virtualenvs\kdocweb-1PRTDUa5-py3.9\lib\site-packages\django\utils\decorators.py", line 130, in _wrapped_view
    response = view_func(request, *args, **kwargs)
  File "C:\Users\username\AppData\Local\pypoetry\Cache\virtualenvs\kdocweb-1PRTDUa5-py3.9\lib\site-packages\django\views\decorators\cache.py", line 44, in _wrapped_view_func
    response = view_func(request, *args, **kwargs)
  File "C:\Users\username\AppData\Local\pypoetry\Cache\virtualenvs\kdocweb-1PRTDUa5-py3.9\lib\site-packages\django\contrib\admin\sites.py", line 232, in inner
    return view(request, *args, **kwargs)
  File "C:\Users\username\AppData\Local\pypoetry\Cache\virtualenvs\kdocweb-1PRTDUa5-py3.9\lib\site-packages\django\contrib\admin\sites.py", line 417, in autocomplete_view
    return AutocompleteJsonView.as_view(admin_site=self)(request)
  File "C:\Users\username\AppData\Local\pypoetry\Cache\virtualenvs\kdocweb-1PRTDUa5-py3.9\lib\site-packages\django\views\generic\base.py", line 70, in view
    return self.dispatch(request, *args, **kwargs)
  File "C:\Users\username\AppData\Local\pypoetry\Cache\virtualenvs\kdocweb-1PRTDUa5-py3.9\lib\site-packages\django\views\generic\base.py", line 98, in dispatch
    return handler(request, *args, **kwargs)
  File "C:\Users\username\AppData\Local\pypoetry\Cache\virtualenvs\kdocweb-1PRTDUa5-py3.9\lib\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 "C:\Users\username\AppData\Local\pypoetry\Cache\virtualenvs\kdocweb-1PRTDUa5-py3.9\lib\site-packages\django\contrib\admin\views\autocomplete.py", line 65, in process_request
    raise PermissionDenied from e
django.core.exceptions.PermissionDenied

The issue is the same of ticket https://code.djangoproject.com/ticket/32659 and it is still not resolved in version 3.2.9.
Downgrading to version 3.1.13 resolves the issue and autocomplete fields work as expected.
The previous ticket was closed with no solution. There is no issue with multiple url definition in my case, downgrading is a workaround but the last LTS version of Django is 3.2.X and here the bug is present.
If the issue is a configuration problem, please give an hint on the solution.
If not, please manage the ticket accordingly.

Change History (3)

comment:1 by Tim Graham, 3 years ago

Component: Uncategorizedcontrib.admin
Resolution: duplicate
Status: newclosed

It seems to be the same issue as the ticket you linked. "app_label" isn't being included in the autocomplete request which suggests that autocomplete.js hasn't been updated to the Django 3.2. version. See TicketClosingReasons/UseSupportChannels if you need help debugging the problem. If you confirm a problem in Django, feel free to reopen with an explanation.

comment:2 by Gianluca Romanin, 3 years ago

It seems to be the same issue as the ticket you linked.

"app_label" isn't being included in the autocomplete request which suggests that autocomplete.js hasn't been updated to the Django 3.2. version.

I'm sorry, but autocomplete.js is code from the Django project? Maybe I'm missing something.
You said that hasn't been updated to the Django 3.2. version, but I'm not using django-autocomplete-light or an external addon for this.
There is no cache issue in the browser, I've tested with incognito mode and there is no improvement.
Collectstatic does not change the thing either.
Autocomplete.js should be updated in the Django base code or in my code?

Note: See TracTickets for help on using tickets.
Back to Top