Default severity: info · Applicability: safe · Category: queryset
Detects for x in list(qs): where qs is a queryset-shaped expression. Wrapping the queryset in list() forces immediate full evaluation and allocates a separate list holding every row before the first loop iteration runs. The model instances are not duplicated — the queryset caches the same objects — but the extra container is pure overhead, and QuerySets are already iterable, so dropping the wrapper removes it. Note that iterating a queryset directly is not streaming either: it still fills _result_cache with the whole result set. Chunked reads over a large table need an explicit .iterator(), which list() would defeat. The QuickFix (“Drop list() and iterate directly”) removes only the list(...) wrapper and is safe to auto-apply.
for user in list(User.objects.filter(is_active=True)):
send_digest(user)
for user in User.objects.filter(is_active=True):
send_digest(user)
# orm-lens-disable-next-line DOL006
Only call list() deliberately — e.g. to snapshot results before mutating rows inside the loop; suppress the finding in that case. Or per-workspace in .vscode/settings.json: {"djangoOrmLens.rules": {"DOL006": "off"}}.