[Django] #34652: Async support in admin view - 'coroutine' object has no attribute 'has_header'

1 view
Skip to first unread message

Django

unread,
Jun 13, 2023, 9:35:55 AM6/13/23
to django-...@googlegroups.com
#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 | Keywords: async
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
------------------------------------------+------------------------
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.

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

Django

unread,
Jun 13, 2023, 9:42:07 AM6/13/23
to django-...@googlegroups.com
#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:

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(

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

--

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

Reply all
Reply to author
Forward
0 new messages