#34652 closed New feature (wontfix)

Async support in admin view

Reported by: Olivier Martin Owned by: nobody
Component: contrib.admin Version: 4.2
Severity: Normal Keywords: async
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Olivier Martin)

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.

Change History (2)

comment:1 by Olivier Martin, 16 months ago

Description: modified (diff)

comment:2 by Mariusz Felisiak, 16 months ago

Component: Uncategorizedcontrib.admin
Resolution: wontfix
Status: newclosed
Summary: Async support in admin view - 'coroutine' object has no attribute 'has_header'Async support in admin view
Type: BugNew feature

Thanks for the ticket.

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.

You also won't find in docs that it is supported. I don't think we should bring async support to the admin. You can start a discussion on the DevelopersMailingList (if you don't agree), where you'll reach a wider audience and see what other think, and follow the guidelines with regards to requesting features.

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