[Django] #32228: csrf_exempt decorator async support

11 views
Skip to first unread message

Django

unread,
Nov 26, 2020, 12:41:53 PM11/26/20
to django-...@googlegroups.com
#32228: csrf_exempt decorator async support
--------------------------------------------+------------------------
Reporter: André Zanghelini | Owner: nobody
Type: New feature | Status: new
Component: CSRF | Version: 3.1
Severity: Normal | Keywords: async
Triage Stage: Unreviewed | Has patch: 1
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
--------------------------------------------+------------------------
After losing an entire day with a cryptic message telling me my view:

> didn't return an HttpResponse object. It returned an unawaited coroutine
instead. You may need to add an 'await' into your view.

Even though the function was a literal single line `return
HttpResponse('a')`. On the next day I found out the problem was because I
was using the `csrf_exempt` decorator.

This patch 'fixes' that, allowing this decorator to be used by async
functions as well.

Couldn't find how to make an automated test for that so it's not included,
someone else has to create it or guide me on where and how to do it.

Flake8 didn't complain and there's no need for extra documentation as it
just improves async support in more existing features.

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

Django

unread,
Nov 26, 2020, 12:45:32 PM11/26/20
to django-...@googlegroups.com
#32228: csrf_exempt decorator async support
----------------------------------+--------------------------------------

Reporter: André Zanghelini | Owner: nobody
Type: New feature | Status: new
Component: CSRF | Version: 3.1
Severity: Normal | Resolution:

Keywords: async | Triage Stage: Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
----------------------------------+--------------------------------------
Changes (by André Zanghelini):

* needs_tests: 0 => 1


Old description:

> After losing an entire day with a cryptic message telling me my view:
>
> > didn't return an HttpResponse object. It returned an unawaited
> coroutine instead. You may need to add an 'await' into your view.
>
> Even though the function was a literal single line `return
> HttpResponse('a')`. On the next day I found out the problem was because I
> was using the `csrf_exempt` decorator.
>
> This patch 'fixes' that, allowing this decorator to be used by async
> functions as well.
>
> Couldn't find how to make an automated test for that so it's not
> included, someone else has to create it or guide me on where and how to
> do it.
>
> Flake8 didn't complain and there's no need for extra documentation as it
> just improves async support in more existing features.

New description:

After losing an entire day with a cryptic message telling me my view:

> didn't return an HttpResponse object. It returned an unawaited coroutine
instead. You may need to add an 'await' into your view.

Even though the function was a literal single line `return
HttpResponse('a')`. On the next day I found out the problem was because I
was using the `csrf_exempt` decorator.

This patch 'fixes' that, allowing this decorator to be used by async
functions as well.

Couldn't find how to make an automated test for that so it's not included,
someone else has to create it or guide me on where and how to do it.

Flake8 didn't complain and there's no need for extra documentation as it
just improves async support in more existing features.

Code at Github
https://github.com/django/django/pull/13720

--

--
Ticket URL: <https://code.djangoproject.com/ticket/32228#comment:1>

Django

unread,
Nov 26, 2020, 12:48:42 PM11/26/20
to django-...@googlegroups.com
#32228: csrf_exempt decorator async support
----------------------------------+--------------------------------------

Reporter: André Zanghelini | Owner: nobody
Type: New feature | Status: closed
Component: CSRF | Version: 3.1
Severity: Normal | Resolution: duplicate

Keywords: async | Triage Stage: Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
----------------------------------+--------------------------------------
Changes (by Mariusz Felisiak):

* status: new => closed
* resolution: => duplicate


Comment:

Duplicate of #31949.

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

Reply all
Reply to author
Forward
0 new messages