#33795 closed Bug (needsinfo)
Django sync_to_async takes infinite time with asgiref 3.5.1+
Reported by: | parfeniukink | Owned by: | nobody |
---|---|---|---|
Component: | HTTP handling | Version: | 3.2 |
Severity: | Normal | Keywords: | asgiref sync_to_async |
Cc: | Andrew Godwin, Carlton Gibson | Triage Stage: | Unreviewed |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description (last modified by )
Django==3.2.13
asgiref==3.5.2
If you will try to decorate any ORM function with sync_to_async you will wait forever.
asgiref==3.5.0 works fine
# models.py class DTOManager(models.Manager): @sync_to_async def filter(self, *args, **kwargs) -> list[BaseModel]: return [self._dto_mapper(i) for i in self.model.objects.filter(*args, **kwargs)] @sync_to_async def get(self, *args, **kwargs) -> BaseModel: try: return self._dto_mapper(self.model.objects.get(*args, **kwargs)) except self.model.DoesNotExist: raise ObjectNotFound(f"{self.model.__name__} not found") class Hotel(models.Model): id = models.UUIDField(primary_key=True, editable=False) coordinates = models.PointField(null=True) dto_objects = DTOManager(dto_mapper=lambda hotel: HotelDTO(**hotel.curated_data) if hotel else None) objects = models.Manager() # services.py hotels = await Hotel.dto_objects.filter(id=12)
Change History (4)
comment:1 by , 2 years ago
Description: | modified (diff) |
---|
follow-up: 4 comment:2 by , 2 years ago
Cc: | added |
---|---|
Component: | Uncategorized → HTTP handling |
Summary: | Django sync_to_async takes infinite time with asgiref==3.5.2 → Django sync_to_async takes infinite time with asgiref 3.5.1+ |
Version 0, edited 2 years ago by (next)
comment:3 by , 2 years ago
Resolution: | → needsinfo |
---|---|
Status: | new → closed |
Also, it works for me with Django 3.2.13, asgiref 3.5.2 and Python 3.8.10 🤔.
comment:4 by , 2 years ago
Replying to Mariusz Felisiak:
Maybe it's not related but I noticed that
test_request_lifecycle_signals_dispatched_with_thread_sensitive
crashes on thestable/3.2.x
branch withasgiref
3.5.1+
Potential fix: PR.
Note:
See TracTickets
for help on using tickets.
Maybe it's probably not related but I noticed that
test_request_lifecycle_signals_dispatched_with_thread_sensitive
crashes on thestable/3.2.x
branch withasgiref
3.5.1+:As far as I'm aware these issues are caused by asgiref/add57649, however we will not backport 36fa071d6ebd18a61c4d7f1b5c9d17106134bd44 so I would restrict supported version:
setup.cfg
4