[Django] #37124: AccessMixin: object HttpResponseRedirect can't be used in 'await' expression

23 views
Skip to first unread message

Django

unread,
May 28, 2026, 4:35:07 AMMay 28
to django-...@googlegroups.com
#37124: AccessMixin: object HttpResponseRedirect can't be used in 'await'
expression
--------------------------------+-----------------------------------------
Reporter: Johannes Maron | Type: Bug
Status: new | Component: Uncategorized
Version: dev | Severity: Normal
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
--------------------------------+-----------------------------------------
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
--
Ticket URL: <https://code.djangoproject.com/ticket/37124>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
May 28, 2026, 4:45:44 AMMay 28
to django-...@googlegroups.com
#37124: AccessMixin: object HttpResponseRedirect can't be used in 'await'
expression
--------------------------------+--------------------------------------
Reporter: Johannes Maron | Owner: (none)
Type: Bug | Status: new
Component: Uncategorized | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
--------------------------------+--------------------------------------
Comment (by amirreza):

should mention `LoginRequiredMixin` also uses
`request.user.is_authenticated` inside `dispatch`, but it should use
`auser` instead,
which requires awaiting.
--
Ticket URL: <https://code.djangoproject.com/ticket/37124#comment:1>

Django

unread,
May 28, 2026, 5:20:18 AMMay 28
to django-...@googlegroups.com
#37124: AccessMixin: object HttpResponseRedirect can't be used in 'await'
expression
--------------------------------+--------------------------------------
Reporter: Johannes Maron | Owner: ZKY
Type: Bug | Status: assigned
Component: Uncategorized | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
--------------------------------+--------------------------------------
Changes (by ZKY):

* owner: (none) => ZKY
* status: new => assigned

--
Ticket URL: <https://code.djangoproject.com/ticket/37124#comment:2>

Django

unread,
May 28, 2026, 4:15:06 PMMay 28
to django-...@googlegroups.com
#37124: AccessMixin: object HttpResponseRedirect can't be used in 'await'
expression
--------------------------------+--------------------------------------
Reporter: Johannes Maron | Owner: (none)
Type: Bug | Status: new
Component: Uncategorized | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
--------------------------------+--------------------------------------
Changes (by Johannes Maron):

* owner: ZKY => (none)
* status: assigned => new

Comment:

As much as I share your enthusiasm, @ZKY, please be so kind and follow the
[https://docs.djangoproject.com/en/dev/internals/contributing/triaging-
tickets/ ticket workflow] and either wait for triage or do it yourself.
Tickets must be accepted before they are assigned.
--
Ticket URL: <https://code.djangoproject.com/ticket/37124#comment:3>

Django

unread,
May 28, 2026, 11:09:49 PMMay 28
to django-...@googlegroups.com
#37124: AccessMixin: object HttpResponseRedirect can't be used in 'await'
expression
--------------------------------+--------------------------------------
Reporter: Johannes Maron | Owner: (none)
Type: Bug | Status: new
Component: Uncategorized | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
--------------------------------+--------------------------------------
Comment (by ZKY):

Oh, apologies! I didn't realize I could triage and accept the status
myself. I have successfully reproduced this issue locally with a minimal
script now.

I'll update the Triage Stage to 'Accepted', re-assign it to myself, and
open a PR with the sync_to_async and auser() fix this weekend. Thanks for
guiding me through the workflow!
--
Ticket URL: <https://code.djangoproject.com/ticket/37124#comment:4>

Django

unread,
May 28, 2026, 11:10:47 PMMay 28
to django-...@googlegroups.com
#37124: AccessMixin: object HttpResponseRedirect can't be used in 'await'
expression
--------------------------------+------------------------------------
Reporter: Johannes Maron | Owner: ZKY
Type: Bug | Status: assigned
Component: Uncategorized | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
--------------------------------+------------------------------------
Changes (by ZKY):

* owner: (none) => ZKY
* stage: Unreviewed => Accepted
* status: new => assigned

--
Ticket URL: <https://code.djangoproject.com/ticket/37124#comment:5>

Django

unread,
May 30, 2026, 6:35:15 AMMay 30
to django-...@googlegroups.com
#37124: AccessMixin: object HttpResponseRedirect can't be used in 'await'
expression
--------------------------------+------------------------------------
Reporter: Johannes Maron | Owner: zky
Type: Bug | Status: assigned
Component: Uncategorized | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
--------------------------------+------------------------------------
Changes (by zky):

* has_patch: 0 => 1

Comment:

https://github.com/django/django/pull/21378
--
Ticket URL: <https://code.djangoproject.com/ticket/37124#comment:6>

Django

unread,
Jun 1, 2026, 12:23:01 PMJun 1
to django-...@googlegroups.com
#37124: AccessMixin: object HttpResponseRedirect can't be used in 'await'
expression
--------------------------------+------------------------------------
Reporter: Johannes Maron | Owner: zky
Type: Bug | Status: assigned
Component: Uncategorized | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 1
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 1 | UI/UX: 0
--------------------------------+------------------------------------
Changes (by Johannes Maron):

* needs_better_patch: 0 => 1
* needs_docs: 0 => 1

--
Ticket URL: <https://code.djangoproject.com/ticket/37124#comment:7>

Django

unread,
Jun 1, 2026, 8:04:12 PMJun 1
to django-...@googlegroups.com
#37124: AccessMixin: object HttpResponseRedirect can't be used in 'await'
expression
--------------------------------+--------------------------------------
Reporter: Johannes Maron | Owner: zky
Type: New feature | Status: assigned
Component: Uncategorized | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed
Has patch: 1 | Needs documentation: 1
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 1 | UI/UX: 0
--------------------------------+--------------------------------------
Changes (by Mykhailo Havelia):

* stage: Accepted => Unreviewed
* type: Bug => New feature

Comment:

I don't think this is really a bug, it's more that it was never
implemented, so I'd lean toward treating it as a new feature. 🙂

- LoginRequiredMixin
- PermissionRequiredMixin
- UserPassesTestMixin

These all rely heavily on sync code like `request.user`,
`request.user.has_perms`, etc.
Also, `request.user` and `request.auser()` don't share a cache, so you'd
end up doing two separate queries. To avoid that, I think we should adapt
the views for async properly instead of applying partial hot-fixes.

I feel like https://github.com/django/new-features is the right place to
discuss both the solution and the future design.

What do you all think?
--
Ticket URL: <https://code.djangoproject.com/ticket/37124#comment:8>

Django

unread,
Jun 2, 2026, 4:12:35 AMJun 2
to django-...@googlegroups.com
#37124: AccessMixin: object HttpResponseRedirect can't be used in 'await'
expression
-------------------------------------+-------------------------------------
Reporter: Johannes Maron | Owner: zky
Type: New feature | Status: closed
Component: Uncategorized | Version: dev
Severity: Normal | Resolution:
| needsnewfeatureprocess
Keywords: | Triage Stage:
| Unreviewed
Has patch: 1 | Needs documentation: 1
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Carlton Gibson):

* resolution: => needsnewfeatureprocess
* status: assigned => closed

Comment:

Yes, these mixins were never in-scope for allowing View to define
asynchronous handlers. (So New Feature is correct.)

Whilst I disagree with Mykhailo about duplicating View in a separate async
version, I agree that some discussion of how to proceed is called for.

> ... so you'd end up doing two separate queries ...

Yes, any async version here would need to ensure it was using the same
pathways as the view it's going to be applied to.
--
Ticket URL: <https://code.djangoproject.com/ticket/37124#comment:9>

Django

unread,
Jun 2, 2026, 5:00:08 AMJun 2
to django-...@googlegroups.com
#37124: AccessMixin: object HttpResponseRedirect can't be used in 'await'
expression
-------------------------------------+-------------------------------------
Reporter: Johannes Maron | Owner: zky
Type: New feature | Status: closed
Component: Generic views | Version: dev
Severity: Normal | Resolution:
| needsnewfeatureprocess
Keywords: | Triage Stage:
| Unreviewed
Has patch: 1 | Needs documentation: 1
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Carlton Gibson):

* component: Uncategorized => Generic views

--
Ticket URL: <https://code.djangoproject.com/ticket/37124#comment:10>

Django

unread,
Jun 2, 2026, 5:00:17 AMJun 2
to django-...@googlegroups.com
#37124: AccessMixin: object HttpResponseRedirect can't be used in 'await'
expression
-------------------------------------+-------------------------------------
Reporter: Johannes Maron | Owner: zky
Type: New feature | Status: closed
Component: Generic views | Version: dev
Severity: Normal | Resolution:
| needsnewfeatureprocess
Keywords: | Triage Stage:
| Unreviewed
Has patch: 1 | Needs documentation: 1
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Carlton Gibson):

* easy: 1 => 0

--
Ticket URL: <https://code.djangoproject.com/ticket/37124#comment:11>

Django

unread,
Jun 2, 2026, 8:34:13 AMJun 2
to django-...@googlegroups.com
#37124: AccessMixin: object HttpResponseRedirect can't be used in 'await'
expression
-------------------------------------+-------------------------------------
Reporter: Johannes Maron | Owner: zky
Type: New feature | Status: closed
Component: Generic views | Version: dev
Severity: Normal | Resolution:
| needsnewfeatureprocess
Keywords: | Triage Stage:
| Unreviewed
Has patch: 1 | Needs documentation: 1
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Johannes Maron):

I was suspicious when I transported the issue here already. It looked like
a pretty big oversight.

That being said, should we maybe update the docs to reflect the
limitation? Not everyone in the community can draw on the level of
experience you two have with this code base.

A small note is probably sufficient, right?
--
Ticket URL: <https://code.djangoproject.com/ticket/37124#comment:12>
Reply all
Reply to author
Forward
0 new messages