#31582: Django template engine render pre-fetches data even when iterator() is
used
---------------------------------+------------------------------------
Reporter: Sümer Cip | Owner: nobody
Type: New feature | Status: new
Component: Template system | Version: 3.0
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
---------------------------------+------------------------------------
Comment (by Keryn Knight):
Yielding for all rendering rather than build up the `nodelist` would
presumably assist in fixing the problem, but the problem itself would
still have to remain as long as `revcounter` and `revcounter0` are
documented as being there (I've no idea who'd use those, but presumably
they exist for a reason). For `last` you can probably rework the loop to
be based around using `next(...)` to find out if there *is* another item
to yield, if there's not. That's last. Similarly for empty nodes rendering
you can check whether the first `next()` raised `StopIteration`
But until `revcounter` and `revcounter0` become optional (ie: the
guarantee is only made if the `items` has a `__len__`) you can't avoid
consuming the iterator to find out the overall span. I certainly don't
think adding another argument is a good idea, because you could then end
up with something absurd like `{% for x in mymodel.objects.all.iterator
iterator %}` or `{% for x in mymodel.objects.all iterator %}`, right?
which both look like typos or accidents.
I don't know if the exception made by doing
`reversed(mymodel.objects.all().iterator())` would get swallowed by DTL or
surfaced, but that'd be another consideration. If it's surfaced I think
that's fine, if it's not that's ''another'' issue.
--
Ticket URL: <https://code.djangoproject.com/ticket/31582#comment:10>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/064.2182edcb4943f2df351559af474d41a3%40djangoproject.com.