Opened 17 months ago

Last modified 17 months ago

#34652 closed New feature

Async support in admin view - 'coroutine' object has no attribute 'has_header' — at Initial Version

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

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.

Change History (0)

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