Opened 9 months ago

Closed 8 months ago

Last modified 8 months ago

#35245 closed Bug (invalid)

Django freezes on DRF's APIView.

Reported by: Luis Grau Martín Maldonado Owned by: nobody
Component: Database layer (models, ORM) Version: 5.0
Severity: Normal Keywords: ORM, async, bug
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

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.

Change History (7)

comment:1 by Mariusz Felisiak, 9 months ago

Have you tried with the latest uvicorn or with daphne?

in reply to:  1 ; comment:2 by Luis Grau Martín Maldonado, 9 months ago

Replying to 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.

in reply to:  1 comment:3 by Luis Grau Martín Maldonado, 9 months ago

Replying to Mariusz Felisiak:

Have you tried with the latest uvicorn or with daphne?

I also added daphne and still happens

comment:4 by willzhao, 9 months ago

Tried to write a UT in https://github.com/django/django/blob/b9d539cca79d8100b24b30fabdb21d10154634ec/tests/async/test_async_queryset.py based on OP's case: https://github.com/LuisGMM/django_bug/blob/a43fb2584c7a15ecd2ada16b9f90fe1df7fe841c/project/app/providers/base.py#L8 .

    async def test_afirst_gather(self):
        instance = await asyncio.gather(*[SimpleModel.objects.afirst()])
        self.assertEqual(instance[0], self.s1)

        instance = await asyncio.gather(SimpleModel.objects.filter(field=4).afirst())
        self.assertIsNone(instance[0])

This UT works fine so I think the issue is not related to asyncio.gather and async ORM call.

Version 2, edited 9 months ago by willzhao (previous) (next) (diff)

in reply to:  2 comment:5 by Natalia Bidart, 9 months ago

Replying to Luis Grau Martín Maldonado:

Replying to 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?

comment:6 by Mariusz Felisiak, 8 months ago

Resolution: needsinfo
Status: newclosed

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.

comment:7 by Mariusz Felisiak, 8 months ago

Resolution: needsinfoinvalid
Summary: Django freezes on async views with asycio.gather and an async ORM callDjango freezes on DRF's APIView.

As far as I'm aware, APIView is not async-compatible so you can try to request a new feature in the Django REST framework.

Note: See TracTickets for help on using tickets.
Back to Top