#28001: Possible unnecessary code if ForNode.render()
------------------------------------------------+------------------------
Reporter: Baptiste Mispelon | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: Template system | Version: 1.10
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
------------------------------------------------+------------------------
The code for `ForNode.render()` [1] has a bit of code with a comment that
reads:
{{{
# The loop variables were pushed on to the context so pop them
# off again. This is necessary because the tag lets the length
# of loopvars differ to the length of each set of items and we
# don't want to leave any vars from the previous loop on the
# context.
}}}
I believe this sentence is incorrect, because `{% for ... %}` raises an
error when there's a mismatch between the variable count and the number of
items retrieve during iteration (this behavior is tested explicitly [2]).
I did a bit of digging and this comment was correct when it was added
(16269c4d0a5d2e61c7555fec438440abee9be9f5) but the error-raising feature
was added after that.
When removing the `context.pop()` just after that comment, the test suite
still passes which indicates that either the code is unnecessary, or it's
untested.
[1]
https://github.com/django/django/blob/70197241017575b60973b038c8f68dcb18526110/django/template/defaulttags.py#L213-L219
[2]
https://github.com/django/django/blob/70197241017575b60973b038c8f68dcb18526110/tests/template_tests/syntax_tests/test_for.py#L157
--
Ticket URL: <https://code.djangoproject.com/ticket/28001>
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 post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/052.faf9e5b08de54e45782e2e6b60426385%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.