#34998: Raising a StopIteration in asynchronous mode hangs the request
--------------------------------------------+------------------------
Reporter: Clément Escolano | Owner: nobody
Type: Uncategorized | Status: new
Component: Uncategorized | Version: 4.2
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
--------------------------------------------+------------------------
When using Django in Asynchronous mode, if some code raises a
`StopIteration` error (generally when calling `next()` on an empty
generator), the request hangs. I think Django should handle the error
gracefully (display a 500 error page) instead.
Basically, when the code raises a `StopIteration` error, the following is
displayed and the request hangs:
{{{
TypeError: StopIteration interacts badly with generators and cannot be
raised into a Future
}}}
I have reproduce the issue with a minimal project here: https://github.com
/clement-escolano/django-stopiteration
Relevant file is `stopiteration/views.py` which is a view called on
`/error` endpoint and contains:
{{{
def error(request):
next(i for i in [])
return None
}}}
The Django application must be run with asynchronous support. For instance
with: `uvicorn test_stopiteration.asgi:application`.
--
Ticket URL: <https://code.djangoproject.com/ticket/34998>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/0107018c1617ddbb-85f9e517-17ca-487f-a424-9e137085a93f-000000%40eu-central-1.amazonses.com.