Opened 12 months ago
Closed 9 months ago
#35030 closed New feature (fixed)
Make django.contrib.auth decorators work with async functions.
Reported by: | Mike Lissner | Owned by: | Dingning |
---|---|---|---|
Component: | contrib.auth | Version: | dev |
Severity: | Normal | Keywords: | async, decorator |
Cc: | Jon Janzen, Dingning, Ben Lomax | Triage Stage: | Ready for checkin |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
We're slowly moving our code base over to async views and tests. Django 5.0 is a big leap forward for this, but we've found that there's still no async version of the @login_required decorator.
We're working around it with some funky decorator usage:
@sync_to_async @login_required @async_to_sync async def our_view(request):
Buuuut, it'd be great not to need to do all this and to either have an async version of login_required (@alogin_required, perhaps?) or for it to just work with async views.
I don't think there's an open issue for this, but amusingly, in a comment 11 months ago, Carlton Gibson touched on making login_required work with async, but he thought it'd take another five years. Perhaps we can do better. :)
Change History (18)
comment:1 by , 12 months ago
Cc: | added |
---|---|
Summary: | No async version of login_required → Make django.contrib.auth decoratos to work with async functions. |
Triage Stage: | Unreviewed → Accepted |
comment:2 by , 12 months ago
Thank you for CC'ing me. I will study how this function can be implemented, and consider whether I can take on this ticket. I will reply within a day.
comment:3 by , 12 months ago
Summary: | Make django.contrib.auth decoratos to work with async functions. → Make django.contrib.auth decorators work with async functions. |
---|
comment:4 by , 12 months ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
OK, I have achieved a simple demo, I think I can work on this ticket. I'll I will improve my code further, then submit a PR as soon as possible.
comment:5 by , 11 months ago
Has patch: | set |
---|---|
Needs documentation: | set |
comment:6 by , 11 months ago
Patch needs improvement: | set |
---|
Here is my PR.
https://github.com/django/django/pull/17621
comment:7 by , 11 months ago
Hello Dingning, thanks for your work on this ticket. Once your PR is ready for review, please unset the flags "Patch needs improvement" and "Needs documentation" so it appears in the review queue (docs about this).
comment:8 by , 11 months ago
Patch needs improvement: | unset |
---|
comment:9 by , 11 months ago
Patch needs improvement: | set |
---|
comment:10 by , 10 months ago
Hi guys, I created a topic to discuss, welcome to chat here(https://forum.djangoproject.com/t/about-async-version-of-the-login-required-decorator/27077)
comment:11 by , 10 months ago
Needs documentation: | unset |
---|---|
Patch needs improvement: | unset |
comment:12 by , 10 months ago
Needs tests: | set |
---|---|
Patch needs improvement: | set |
comment:13 by , 9 months ago
Needs tests: | unset |
---|---|
Patch needs improvement: | unset |
comment:14 by , 9 months ago
Hello, dear reviewers. I have updated my commit. Could you please review the pull request?
comment:15 by , 9 months ago
Patch needs improvement: | set |
---|
comment:17 by , 9 months ago
Patch needs improvement: | unset |
---|---|
Triage Stage: | Accepted → Ready for checkin |
Related to #34391 and #31949.