#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)
follow-ups: 2 3 comment:1 by , 9 months ago
follow-up: 5 comment:2 by , 9 months ago
Replying to Mariusz Felisiak:
Have you tried with the latest
uvicorn
or withdaphne
?
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.
comment:3 by , 9 months ago
Replying to Mariusz Felisiak:
Have you tried with the latest
uvicorn
or withdaphne
?
I also added daphne and still happens
comment:4 by , 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.
comment:5 by , 9 months ago
Replying to Luis Grau Martín Maldonado:
Replying to Mariusz Felisiak:
Have you tried with the latest
uvicorn
or withdaphne
?
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 , 8 months ago
Resolution: | → needsinfo |
---|---|
Status: | new → closed |
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 , 8 months ago
Resolution: | needsinfo → invalid |
---|---|
Summary: | Django freezes on async views with asycio.gather and an async ORM call → Django 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.
Have you tried with the latest
uvicorn
or withdaphne
?