#24555: Wrong content in inclusion templatetags with variable parent template
-------------------------------------+-------------------------------------
Reporter: benjaminrigaud | Owner: Tim
| Graham <timograham@…>
Type: Bug | Status: closed
Component: Template system | Version: 1.8rc1
Severity: Release blocker | Resolution: fixed
Keywords: templatetags | Triage Stage: Ready for
extends block cache | checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by nealtodd):
Although the ticket is closed I'm adding this comment in case anyone
stumbles across the same esoteric gotcha I came across related to this
change:
After updating a project from 1.8c1 to 1.8 a bunch of tests that had been
running cleanly started failing on `assertFormError` in the format of
`AssertionError: The form 'form' in context X does not contain the field
'foo'`.
Long story short, the template had a 'main' form that was supplied via a
context variable named 'form', but the base template also used an
inclusion tag to render a site search form, and the inclusion tag's
template was also supplied via a context variable named 'form'. The
caching introduced in this commit meant that the inclusion tag's template
now also appeared in the `response.context`, and so, when calling
`self.assertFormError(response, "form", "foo", "expected error message")`
[https://github.com/django/django/blob/master/django/test/testcases.py#L386
assertFormError] looped over the context and found a form (the search
form) without the intended field `foo` (as well as finding it as expected
on the main form).
The simple fix in this case was to scope the context key name of the
search form to, e.g. 'search_form' for the inclusion tag's template.
However as, ordinarily, a clash of key names used in the contexts for
different templates shouldn't matter, I thought I'd note it here as it
left me scratching my head for a while until I tracked in down.
--
Ticket URL: <https://code.djangoproject.com/ticket/24555#comment:11>
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/072.832a585d3ac31df4983ac520b7e1ed20%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.