Opened 45 minutes ago

Last modified 16 seconds ago

#37124 assigned Bug

AccessMixin: object HttpResponseRedirect can't be used in 'await' expression

Reported by: Johannes Maron Owned by: ZKY
Component: Uncategorized Version: dev
Severity: Normal Keywords:
Cc: Johannes Maron Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no

Description

The redirect response in AccessMixin.handle_no_permission isn't async compatible.

If you have access, everything works fine, since all HTTP method handlers are async and return coroutines; only if you lack permissions or are unauthenticated is the redirect response synchronous.

With access to view_is_async it should be a fairly easy fix to have handle_no_permission return a coroutine.

Thanks to @amirreza-sf80 for reporting:
https://github.com/django/new-features/issues/162#issuecomment-4562082172

I could find the bug on Stack Overflow as well, but no ticket on Trac:
https://stackoverflow.com/questions/66512353/using-loginrequiredmixin-with-async-views

Change History (2)

comment:1 by amirreza, 35 minutes ago

should mention LoginRequiredMixin also uses request.user.is_authenticated inside dispatch, but it should use auser instead,
which requires awaiting.

comment:2 by ZKY, 16 seconds ago

Owner: set to ZKY
Status: newassigned
Note: See TracTickets for help on using tickets.
Back to Top