#34652: Async support in admin view - 'coroutine' object has no attribute
'has_header'
--------------------------------+--------------------------------------
     Reporter:  Olivier Martin  |                    Owner:  nobody
         Type:  Bug             |                   Status:  new
    Component:  Uncategorized   |                  Version:  4.2
     Severity:  Normal          |               Resolution:
     Keywords:  async           |             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 Olivier Martin:

Old description:

> I wanted to change one of my admin page to leverage async support.
>
> I tried this simple example (based on the Django tutorial):
>
> {{{
> from django.contrib import admin
>
> from .models import Question
>
> class QuestionAdmin(admin.ModelAdmin):
>         async def change_view(self, request, object_id, form_url='',
> extra_context=None):
>                 return super(SensorAdmin, self).change_view(
>                         request, object_id, form_url,
> extra_context=extra_context,
>                 )
>
> admin.site.register(Question, QuestionAdmin)
> }}}
>
> and started with runserver: `python3 ./mysite/manage.py runserver` and
> when accessing on the page:
>
> {{{
> Internal Server Error: /admin/polls/question/1/change/
> Traceback (most recent call last):
>   File "/home/olivier/.local/lib/python3.10/site-
> packages/django/core/handlers/exception.py", line 55, in inner
>     response = get_response(request)
>   File "/home/olivier/.local/lib/python3.10/site-
> packages/django/core/handlers/base.py", line 197, in _get_response
>     response = wrapped_callback(request, *callback_args,
> **callback_kwargs)
>   File "/home/olivier/.local/lib/python3.10/site-
> packages/django/contrib/admin/options.py", line 688, in wrapper
>     return self.admin_site.admin_view(view)(*args, **kwargs)
>   File "/home/olivier/.local/lib/python3.10/site-
> packages/django/utils/decorators.py", line 134, in _wrapper_view
>     response = view_func(request, *args, **kwargs)
>   File "/home/olivier/.local/lib/python3.10/site-
> packages/django/views/decorators/cache.py", line 63, in
> _wrapper_view_func
>     add_never_cache_headers(response)
>   File "/home/olivier/.local/lib/python3.10/site-
> packages/django/utils/cache.py", line 292, in add_never_cache_headers
>     patch_response_headers(response, cache_timeout=-1)
>   File "/home/olivier/.local/lib/python3.10/site-
> packages/django/utils/cache.py", line 283, in patch_response_headers
>     if not response.has_header("Expires"):
> AttributeError: 'coroutine' object has no attribute 'has_header'
> }}}
>
> Note: same error when running in Daphne with asgi.
>
> I read the Django Async doc
> https://docs.djangoproject.com/en/4.2/topics/async/#async-views and I
> could not see any restriction on using async in admin pages.

New description:

 I wanted to change one of my admin page to leverage async support.

 I tried this simple example (based on the Django tutorial):

 {{{
 from django.contrib import admin

 from .models import Question

 class QuestionAdmin(admin.ModelAdmin):
         async def change_view(self, request, object_id, form_url='',
 extra_context=None):
                 return super(QuestionAdmin, self).change_view(
                         request, object_id, form_url,
 extra_context=extra_context,
                 )

 admin.site.register(Question, QuestionAdmin)
 }}}

 and started with runserver: `python3 ./mysite/manage.py runserver` and
 when accessing on the page:

 {{{
 Internal Server Error: /admin/polls/question/1/change/
 Traceback (most recent call last):
   File "/home/olivier/.local/lib/python3.10/site-
 packages/django/core/handlers/exception.py", line 55, in inner
     response = get_response(request)
   File "/home/olivier/.local/lib/python3.10/site-
 packages/django/core/handlers/base.py", line 197, in _get_response
     response = wrapped_callback(request, *callback_args,
 **callback_kwargs)
   File "/home/olivier/.local/lib/python3.10/site-
 packages/django/contrib/admin/options.py", line 688, in wrapper
     return self.admin_site.admin_view(view)(*args, **kwargs)
   File "/home/olivier/.local/lib/python3.10/site-
 packages/django/utils/decorators.py", line 134, in _wrapper_view
     response = view_func(request, *args, **kwargs)
   File "/home/olivier/.local/lib/python3.10/site-
 packages/django/views/decorators/cache.py", line 63, in _wrapper_view_func
     add_never_cache_headers(response)
   File "/home/olivier/.local/lib/python3.10/site-
 packages/django/utils/cache.py", line 292, in add_never_cache_headers
     patch_response_headers(response, cache_timeout=-1)
   File "/home/olivier/.local/lib/python3.10/site-
 packages/django/utils/cache.py", line 283, in patch_response_headers
     if not response.has_header("Expires"):
 AttributeError: 'coroutine' object has no attribute 'has_header'
 }}}

 Note: same error when running in Daphne with asgi.

 I read the Django Async doc
 https://docs.djangoproject.com/en/4.2/topics/async/#async-views and I
 could not see any restriction on using async in admin pages.

--

-- 
Ticket URL: <https://code.djangoproject.com/ticket/34652#comment:1>
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/01070188b4fdf96c-605257ea-5813-4a70-908c-d61452779a8d-000000%40eu-central-1.amazonses.com.

Reply via email to