Changes between Version 3 and Version 4 of Ticket #33735, comment 8


Ignore:
Timestamp:
Oct 11, 2022, 9:05:00 AM (2 years ago)
Author:
Carlton Gibson

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #33735, comment 8

    v3 v4  
    1818Under WSGI you'd continue to provide a sync iterator and everything would work as it is already.
    1919
    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.
     20For 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 contfiguration if not desired) saying that folks should use an appropriate generator type in this case.
    2121
    2222Note 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:
Back to Top