[Django] #35245: Django freezes on async views with asycio.gather and an async ORM call

18 views
Skip to first unread message

Django

unread,
Feb 22, 2024, 10:56:01 AM2/22/24
to django-...@googlegroups.com
#35245: Django freezes on async views with asycio.gather and an async ORM call
-------------------------------------+-------------------------------------
Reporter: Luis Grau | Owner: nobody
Martín Maldonado |
Type: Bug | Status: new
Component: Database | Version: 5.0
layer (models, ORM) |
Severity: Normal | Keywords: ORM, async, bug
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
This issue is very similar to this one:
[https://code.djangoproject.com/ticket/34747#ticket]

However, there is only the necessary middleware:

{{{
MIDDLEWARE = [
"django.contrib.sessions.middleware.SessionMiddleware",
"django.contrib.auth.middleware.AuthenticationMiddleware",
"django.contrib.messages.middleware.MessageMiddleware",
]
}}}

Instead of putting here snippets, I have created a repo with a dockerfile,
docker-compose and minimum project that shows the problem
[https://github.com/LuisGMM/django_bug]

Inside it you can do {{{docker-compose up}}} and access to
[http://0.0.0.0:8000/endpoint/] to check the view with the problem. If the
lines in MyProvider are commented, it works.
--
Ticket URL: <https://code.djangoproject.com/ticket/35245>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Feb 22, 2024, 12:51:50 PM2/22/24
to django-...@googlegroups.com
#35245: Django freezes on async views with asycio.gather and an async ORM call
-------------------------------------+-------------------------------------
Reporter: Luis Grau Martín | Owner: nobody
Maldonado |
Type: Bug | Status: new
Component: Database layer | Version: 5.0
(models, ORM) |
Severity: Normal | Resolution:
Keywords: ORM, async, bug | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Mariusz Felisiak):

Have you tried with the latest `uvicorn` or with `daphne`?
--
Ticket URL: <https://code.djangoproject.com/ticket/35245#comment:1>

Django

unread,
Feb 22, 2024, 1:43:31 PM2/22/24
to django-...@googlegroups.com
#35245: Django freezes on async views with asycio.gather and an async ORM call
-------------------------------------+-------------------------------------
Reporter: Luis Grau Martín | Owner: nobody
Maldonado |
Type: Bug | Status: new
Component: Database layer | Version: 5.0
(models, ORM) |
Severity: Normal | Resolution:
Keywords: ORM, async, bug | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Luis Grau Martín Maldonado):

Replying to [comment:1 Mariusz Felisiak]:
> Have you tried with the latest `uvicorn` or with `daphne`?

I have removed the version requirements of all dependencies so pip
installs the latest ones and just checked it still happens at least with
uvicorn.
--
Ticket URL: <https://code.djangoproject.com/ticket/35245#comment:2>

Django

unread,
Feb 22, 2024, 1:48:40 PM2/22/24
to django-...@googlegroups.com
#35245: Django freezes on async views with asycio.gather and an async ORM call
-------------------------------------+-------------------------------------
Reporter: Luis Grau Martín | Owner: nobody
Maldonado |
Type: Bug | Status: new
Component: Database layer | Version: 5.0
(models, ORM) |
Severity: Normal | Resolution:
Keywords: ORM, async, bug | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Luis Grau Martín Maldonado):

Replying to [comment:1 Mariusz Felisiak]:
> Have you tried with the latest `uvicorn` or with `daphne`?

I also added daphne and still happens
--
Ticket URL: <https://code.djangoproject.com/ticket/35245#comment:3>

Django

unread,
Feb 23, 2024, 2:43:32 AM2/23/24
to django-...@googlegroups.com
#35245: Django freezes on async views with asycio.gather and an async ORM call
-------------------------------------+-------------------------------------
Reporter: Luis Grau Martín | Owner: nobody
Maldonado |
Type: Bug | Status: new
Component: Database layer | Version: 5.0
(models, ORM) |
Severity: Normal | Resolution:
Keywords: ORM, async, bug | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by willzhao):

[https://github.com/LuisGMM/django_bug/blob/a43fb2584c7a15ecd2ada16b9f90fe1df7fe841c/project/app/providers/base.py#L8]
{{{#!python
items_lists = await asyncio.gather(*[MyProvider().get()]) # blocked
items_lists = await asyncio.gather(MyModel.objects.afirst()) # blocked
items_lists = await asyncio.gather(MyModel.objects.acreate()) # blocked
items_lists = await MyProvider().get() # works
}}}
It's indeed a weird issue
--
Ticket URL: <https://code.djangoproject.com/ticket/35245#comment:4>

Django

unread,
Feb 23, 2024, 7:51:31 AM2/23/24
to django-...@googlegroups.com
#35245: Django freezes on async views with asycio.gather and an async ORM call
-------------------------------------+-------------------------------------
Reporter: Luis Grau Martín | Owner: nobody
Maldonado |
Type: Bug | Status: new
Component: Database layer | Version: 5.0
(models, ORM) |
Severity: Normal | Resolution:
Keywords: ORM, async, bug | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Natalia Bidart):

Replying to [comment:2 Luis Grau Martín Maldonado]:
> Replying to [comment:1 Mariusz Felisiak]:
> > Have you tried with the latest `uvicorn` or with `daphne`?
>
> I have removed the version requirements of all dependencies so pip
installs the latest ones and just checked it still happens at least with
uvicorn.

To double check, have you also wiped the venv and re-installed all deps?
Or have you `pip install -U` to ensure latest versions are fetched?
--
Ticket URL: <https://code.djangoproject.com/ticket/35245#comment:5>

Django

unread,
Feb 26, 2024, 6:16:46 AM2/26/24
to django-...@googlegroups.com
#35245: Django freezes on async views with asycio.gather and an async ORM call
-------------------------------------+-------------------------------------
Reporter: Luis Grau Martín | Owner: nobody
Maldonado |
Type: Bug | Status: closed
Component: Database layer | Version: 5.0
(models, ORM) |
Severity: Normal | Resolution: needsinfo
Keywords: ORM, async, bug | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

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

Comment:

Hi, thanks for the report, however, I don't think you've explained the
issue in enough detail to confirm a bug in Django. Please reopen the
ticket if you can debug your issue and provide details about why and where
Django is at fault or a sample project that reproduces the issue and
doesn't use 3rd party packages (e.g. Django REST framework). Builtin
middlewares are not at fault, your project hangs even with an empty list
of middlewares and without `django.contrib.admin`,
`django.contrib.sessions`, and `django.contrib.messages` in
`INSTALLED_APPS`.
--
Ticket URL: <https://code.djangoproject.com/ticket/35245#comment:6>
Reply all
Reply to author
Forward
0 new messages