Changes between Version 2 and Version 3 of Ticket #33735, comment 8
- Timestamp:
- Oct 11, 2022, 9:04:23 AM (2 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
Ticket #33735, comment 8
v2 v3 18 18 Under WSGI you'd continue to provide a sync iterator and everything would work as it is already. 19 19 20 For each case, `__iter__` and `__aiter__` we handle the **wrong case** by consuming the iterator in a single step (using the `asgiref.sync` utilities, with `thread_sensitive` for `sync_to_async`) and then yield it out in parts as expected. (This is the performance and memory cost.) We log a **warning** (that may be filtered in a logging content if not desired) saying that folks should use an appropriate generator type in this case.20 For each case, `__iter__` and `__aiter__` we handle the **wrong type of iterator** by consuming the iterator in a single step (using the `asgiref.sync` utilities, with `thread_sensitive` for `sync_to_async`) and then yield it out in parts as expected. (This is the performance and memory cost.) We log a **warning** (that may be filtered in a logging content if not desired) saying that folks should use an appropriate generator type in this case. 21 21 22 22 Note that this is similar to the `__aiter__` implementation on QuerySet, which [https://github.com/django/django/blob/f30c7e381c94f41d361877d8a3e90f8cfb391709/django/db/models/query.py#L397-L405 fetches all the records once inside a single sync_to_async()] to avoid multiple (costly) context switches there: