#33261: Autocomplete field triggers a PermissionDenied error
--------------------------------------------+------------------------
               Reporter:  Gianluca Romanin  |          Owner:  nobody
                   Type:  Bug               |         Status:  new
              Component:  Uncategorized     |        Version:  3.2
               Severity:  Normal            |       Keywords:
           Triage Stage:  Unreviewed        |      Has patch:  0
    Needs documentation:  0                 |    Needs tests:  0
Patch needs improvement:  0                 |  Easy pickings:  0
                  UI/UX:  0                 |
--------------------------------------------+------------------------
 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.

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

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/051.0ba227542dac0a321308e86b10810a9e%40djangoproject.com.

Reply via email to