Re: [Django] #35083: Make django.utils.decorators.method_decorator work with async functions.

74 views
Skip to first unread message

Django

unread,
Jan 3, 2024, 2:31:41 PM1/3/24
to django-...@googlegroups.com
#35083: Make django.utils.decorators.method_decorator work with async functions.
------------------------------+------------------------------------
Reporter: Drew Winstel | Owner: nobody
Type: New feature | Status: new
Component: Utilities | Version: 5.0
Severity: Normal | Resolution:
Keywords: async | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
------------------------------+------------------------------------

Comment (by Drew Winstel):

That makes sense. Thanks, Natalia!

--
Ticket URL: <https://code.djangoproject.com/ticket/35083#comment:2>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Jan 4, 2024, 3:27:54 AM1/4/24
to django-...@googlegroups.com
#35083: Make django.utils.decorators.method_decorator work with async functions.
------------------------------+------------------------------------
Reporter: Drew Winstel | Owner: nobody
Type: New feature | Status: new
Component: Utilities | Version: 5.0
Severity: Normal | Resolution:
Keywords: async | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
------------------------------+------------------------------------

Comment (by Carlton Gibson):

This ticket seems correct (`method_decorator` should work with `async def`
methods).

Out of interest though, `View` standardly has a sync `dispatch`, which
you've overridden here:

{{{
class View1(View):
@method_decorator(ensure_csrf_cookie)
async def dispatch(
self, request: HttpRequest, *args: Any, **kwargs: Any
) -> HttpResponse:
return await super().dispatch(request, *args, **kwargs)

}}}

... so would `method_decorator` work already for the ''usual cases'',
decorating `dispatch`? 🤔

Likely off-topic but just for future context, Drew could you maybe briefly
say how it comes up — I guess the Strawberry base class is `async def` all
the way... or ... 🤔?
Thanks.

--
Ticket URL: <https://code.djangoproject.com/ticket/35083#comment:3>

Django

unread,
Jan 4, 2024, 8:24:48 AM1/4/24
to django-...@googlegroups.com
#35083: Make django.utils.decorators.method_decorator work with async functions.
------------------------------+------------------------------------
Reporter: Drew Winstel | Owner: nobody
Type: New feature | Status: new
Component: Utilities | Version: 5.0
Severity: Normal | Resolution:
Keywords: async | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
------------------------------+------------------------------------

Comment (by Drew Winstel):

> Out of interest though, View standardly has a sync dispatch, which
you've overridden here:

Right, that's because strawberry's `dispatch()` is overridden as well:
https://github.com/strawberry-
graphql/strawberry/blob/main/strawberry/django/views.py#L266-L277

> Likely off-topic but just for future context, Drew could you maybe
briefly say how it comes up — I guess the Strawberry base class is async
def all the way... or ... 🤔?

It does inherit from `django.views.generic.View`, but `dispatch()` is a
clean break from the generic view's version.

Strawberry's view includes the `@csrf_exempt()` decorator, but we (at my
day job) need `@ensure_csrf_cookie()` applied to that view because of
weird node.js things that I don't even pretend to understand. :D

--
Ticket URL: <https://code.djangoproject.com/ticket/35083#comment:4>

Django

unread,
Jan 31, 2024, 7:06:09 AM1/31/24
to django-...@googlegroups.com
#35083: Make django.utils.decorators.method_decorator work with async functions.
------------------------------+------------------------------------
Reporter: Drew Winstel | Owner: nobody
Type: New feature | Status: new
Component: Utilities | Version: 5.0
Severity: Normal | Resolution:
Keywords: async | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
------------------------------+------------------------------------
Comment (by patrick):

@Drew @Carlton is there anything we can do better in the Strawberry Django
View? Happy to make changes there 😊
--
Ticket URL: <https://code.djangoproject.com/ticket/35083#comment:5>

Django

unread,
Jan 31, 2024, 8:21:46 AM1/31/24
to django-...@googlegroups.com
#35083: Make django.utils.decorators.method_decorator work with async functions.
------------------------------+------------------------------------
Reporter: Drew Winstel | Owner: nobody
Type: New feature | Status: new
Component: Utilities | Version: 5.0
Severity: Normal | Resolution:
Keywords: async | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
------------------------------+------------------------------------
Comment (by Carlton Gibson):

@Patrick — I don't think you need to. There's no reason why you can't
reimplement `dispatch`. (Of course if you can get by without doing so,
that's less code, but I don't think it's an issue per se, and this is
still an improvement we can make in Django.)
--
Ticket URL: <https://code.djangoproject.com/ticket/35083#comment:6>

Django

unread,
Jan 31, 2024, 11:42:06 AM1/31/24
to django-...@googlegroups.com
#35083: Make django.utils.decorators.method_decorator work with async functions.
------------------------------+--------------------------------------
Reporter: Drew Winstel | Owner: Gaurav sah
Type: New feature | Status: assigned

Component: Utilities | Version: 5.0
Severity: Normal | Resolution:
Keywords: async | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
------------------------------+--------------------------------------
Changes (by Gaurav sah):

* owner: nobody => Gaurav sah
* status: new => assigned

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

Django

unread,
Jan 31, 2024, 11:49:45 AM1/31/24
to django-...@googlegroups.com
#35083: Make django.utils.decorators.method_decorator work with async functions.
------------------------------+------------------------------------
Reporter: Drew Winstel | Owner: (none)

Type: New feature | Status: new
Component: Utilities | Version: 5.0
Severity: Normal | Resolution:
Keywords: async | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
------------------------------+------------------------------------
Changes (by Gaurav sah):

* owner: Gaurav sah => (none)
* status: assigned => new

--
Ticket URL: <https://code.djangoproject.com/ticket/35083#comment:8>

Django

unread,
Jun 26, 2024, 1:26:21 PM6/26/24
to django-...@googlegroups.com
#35083: Make django.utils.decorators.method_decorator work with async functions.
------------------------------+----------------------------------------
Reporter: Drew Winstel | Owner: Vaarun Sinha
Type: New feature | Status: assigned
Component: Utilities | Version: 5.0
Severity: Normal | Resolution:
Keywords: async | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
------------------------------+----------------------------------------
Changes (by Vaarun Sinha):

* owner: (none) => Vaarun Sinha
* status: new => assigned

--
Ticket URL: <https://code.djangoproject.com/ticket/35083#comment:9>

Django

unread,
Jun 27, 2024, 8:39:55 AM6/27/24
to django-...@googlegroups.com
#35083: Make django.utils.decorators.method_decorator work with async functions.
------------------------------+----------------------------------------
Reporter: Drew Winstel | Owner: Vaarun Sinha
Type: New feature | Status: assigned
Component: Utilities | Version: 5.0
Severity: Normal | Resolution:
Keywords: async | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
------------------------------+----------------------------------------
Comment (by Vaarun Sinha):

I have a patch ready I am just making it ready (writing tests and comments
for it) I will make a PR this week hopefully!
--
Ticket URL: <https://code.djangoproject.com/ticket/35083#comment:10>

Django

unread,
Jul 2, 2024, 10:52:19 AM7/2/24
to django-...@googlegroups.com
#35083: Make django.utils.decorators.method_decorator work with async functions.
------------------------------+----------------------------------------
Reporter: Drew Winstel | Owner: Vaarun Sinha
Type: New feature | Status: assigned
Component: Utilities | Version: 5.0
Severity: Normal | Resolution:
Keywords: async | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
------------------------------+----------------------------------------
Changes (by Carlton Gibson):

* needs_tests: 0 => 1

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

Django

unread,
Jul 3, 2024, 6:13:53 AM7/3/24
to django-...@googlegroups.com
#35083: Make django.utils.decorators.method_decorator work with async functions.
------------------------------+----------------------------------------
Reporter: Drew Winstel | Owner: Vaarun Sinha
Type: New feature | Status: assigned
Component: Utilities | Version: 5.0
Severity: Normal | Resolution:
Keywords: async | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 1
Needs tests: 1 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
------------------------------+----------------------------------------
Changes (by Carlton Gibson):

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

Comment:

Comments on the
[https://github.com/django/django/pull/18329#pullrequestreview-2156030598
PR]. A release note would also be needed.
--
Ticket URL: <https://code.djangoproject.com/ticket/35083#comment:12>

Django

unread,
Jul 5, 2024, 3:44:45 AM7/5/24
to django-...@googlegroups.com
#35083: Make django.utils.decorators.method_decorator work with async functions.
------------------------------+----------------------------------------
Reporter: Drew Winstel | Owner: Vaarun Sinha
Type: New feature | Status: assigned
Component: Utilities | Version: 5.0
Severity: Normal | Resolution:
Keywords: async | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 1
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
------------------------------+----------------------------------------
Changes (by Vaarun Sinha):

* needs_better_patch: 1 => 0
* needs_tests: 1 => 0

--
Ticket URL: <https://code.djangoproject.com/ticket/35083#comment:13>

Django

unread,
Jul 8, 2024, 9:33:48 AM7/8/24
to django-...@googlegroups.com
#35083: Make django.utils.decorators.method_decorator work with async functions.
------------------------------+----------------------------------------
Reporter: Drew Winstel | Owner: Vaarun Sinha
Type: New feature | Status: assigned
Component: Utilities | Version: 5.0
Severity: Normal | Resolution:
Keywords: async | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
------------------------------+----------------------------------------
Changes (by Carlton Gibson):

* needs_docs: 1 => 0

Comment:

[https://github.com/django/django/pull/18346 New PR] looks ready for a
review.
--
Ticket URL: <https://code.djangoproject.com/ticket/35083#comment:14>

Django

unread,
Jul 8, 2024, 11:43:10 AM7/8/24
to django-...@googlegroups.com
#35083: Make django.utils.decorators.method_decorator work with async functions.
------------------------------+----------------------------------------
Reporter: Drew Winstel | Owner: Vaarun Sinha
Type: New feature | Status: assigned
Component: Utilities | Version: dev
Severity: Normal | Resolution:
Keywords: async | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
------------------------------+----------------------------------------
Changes (by Natalia Bidart):

* needs_better_patch: 0 => 1
* needs_tests: 0 => 1
* version: 5.0 => dev

Comment:

Submitted PR would benefit from a wider test coverage and removing some of
the (now) duplicated comments and code.
--
Ticket URL: <https://code.djangoproject.com/ticket/35083#comment:15>

Django

unread,
Aug 7, 2024, 2:37:34 AM8/7/24
to django-...@googlegroups.com
#35083: Make django.utils.decorators.method_decorator work with async functions.
------------------------------+----------------------------------------
Reporter: Drew Winstel | Owner: Vaarun Sinha
Type: New feature | Status: assigned
Component: Utilities | Version: dev
Severity: Normal | Resolution:
Keywords: async | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
------------------------------+----------------------------------------
Changes (by Vaarun Sinha):

* needs_better_patch: 1 => 0
* needs_tests: 1 => 0

--
Ticket URL: <https://code.djangoproject.com/ticket/35083#comment:16>

Django

unread,
Aug 29, 2024, 9:18:47 PM8/29/24
to django-...@googlegroups.com
#35083: Make django.utils.decorators.method_decorator work with async functions.
-------------------------------------+-------------------------------------
Reporter: Drew Winstel | Owner: Vaarun
| Sinha
Type: New feature | Status: assigned
Component: Utilities | Version: dev
Severity: Normal | Resolution:
Keywords: async | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Natalia Bidart):

* stage: Accepted => Ready for checkin

--
Ticket URL: <https://code.djangoproject.com/ticket/35083#comment:17>

Django

unread,
Aug 30, 2024, 7:54:58 AM8/30/24
to django-...@googlegroups.com
#35083: Make django.utils.decorators.method_decorator work with async functions.
-------------------------------------+-------------------------------------
Reporter: Drew Winstel | Owner: Vaarun
| Sinha
Type: New feature | Status: closed
Component: Utilities | Version: dev
Severity: Normal | Resolution: fixed
Keywords: async | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by nessita <124304+nessita@…>):

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

Comment:

In [changeset:"884ce37479b9a250afc8ec02793291484adda6c3" 884ce37]:
{{{#!CommitTicketReference repository=""
revision="884ce37479b9a250afc8ec02793291484adda6c3"
Fixed #35083 -- Updated method_decorator to handle async methods.

Co-authored-by: Natalia <124304+...@users.noreply.github.com>
Co-authored-by: Carlton Gibson <carlton...@noumenal.es>
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/35083#comment:18>
Reply all
Reply to author
Forward
0 new messages