Django: Ticket #1338: Undefined context variables should not resolve to the value of TEMPLATE_STRING_IF_INVALIDhttps://code.djangoproject.com/ticket/1338
<p>
The new TEMPLATE_STRING_IF_INVALID is a useful setting but it seems to have some problems currently. With the current implementation undefined context variables are actually resolved to the value of TEMPLATE_STRING_IF_INVALID. This means that {% if
some_undefined_variable %} can evaluate true. Also <code>FilterExpression</code> is passing the
TEMPLATE_STRING_IF_INVALID value through the filters, which is probably not going to fit with user expectations.
</p>
<p>
Perhaps <code>resolve_variable</code> should be consistently raising an exception
for all unresolvable variables and <code>Node</code> renderers and <code>FilterExpression</code> should be returning TEMPLATE_STRING_IF_INVALID directly where appropriate. This would be slightly backwards
incompatible for people using the guts of the template renderer in their template tags.
</p>
en-usDjangohttps://www.djangoproject.com/s/img/site/hdr_logo.gifhttps://code.djangoproject.com/ticket/1338
Trac 1.2.3HolgerSchurigSat, 27 May 2006 20:07:41 GMThttps://code.djangoproject.com/ticket/1338#comment:1
https://code.djangoproject.com/ticket/1338#comment:1
<p>
When I set
</p>
<pre class="wiki"> #TEMPLATE_STRING_IF_INVALID = "...missing..."
</pre><p>
in my settings.py, then suddenly inside the admin I won't have the header anymore (the blue bar with "Welcome", documentation, change password, logout, the breadcrumps). So I removed this setting immediately.
</p>
<p>
I think this is related to this bug.
</p>
TicketDanielTietzeWed, 31 May 2006 20:22:36 GMTseverity changedhttps://code.djangoproject.com/ticket/1338#comment:2
https://code.djangoproject.com/ticket/1338#comment:2
<ul>
<li><strong>severity</strong>
changed from <em>normal</em> to <em>major</em>
</li>
</ul>
<p>
I'd say this was a major bug, because it makes this setting -- which could be quite useful for debugging template errors -- virtually useless. It makes all {% if [varname] %} evaluate to true and breaks a lot of logic within the template.
</p>
Ticketdjango@…Wed, 31 May 2006 22:22:24 GMThttps://code.djangoproject.com/ticket/1338#comment:3
https://code.djangoproject.com/ticket/1338#comment:3
<p>
Just a note that this is one of the things I fixed in <a class="closed ticket" href="https://code.djangoproject.com/ticket/1400" title="#1400: enhancement: [magic-removal] [patch] proposed update to template system (closed: wontfix)">#1400</a> but that patch seems to have been a little too ambitious to get any loving. Not getting much feedback on what was good and what sucked I didn't get around to breaking the patch down into bite-sized chunks. Unfortunately I no longer have time to work on it at the moment.
</p>
TicketRussell Keith-MageeTue, 04 Jul 2006 01:32:11 GMTowner changedhttps://code.djangoproject.com/ticket/1338#comment:4
https://code.djangoproject.com/ticket/1338#comment:4
<ul>
<li><strong>owner</strong>
changed from <em>Adrian Holovaty</em> to <em>Russell Keith-Magee</em>
</li>
</ul>
TicketRussell Keith-MageeTue, 04 Jul 2006 03:21:44 GMTstatus changed; resolution sethttps://code.djangoproject.com/ticket/1338#comment:5
https://code.djangoproject.com/ticket/1338#comment:5
<ul>
<li><strong>status</strong>
changed from <em>new</em> to <em>closed</em>
</li>
<li><strong>resolution</strong>
set to <em>fixed</em>
</li>
</ul>
<p>
(In <a class="changeset" href="https://code.djangoproject.com/changeset/3268/">[3268]</a>) Fixes <a class="closed ticket" href="https://code.djangoproject.com/ticket/1338" title="#1338: task: Undefined context variables should not resolve to the value of ... (closed: fixed)">#1338</a>, Refs <a class="closed ticket" href="https://code.djangoproject.com/ticket/1400" title="#1400: enhancement: [magic-removal] [patch] proposed update to template system (closed: wontfix)">#1400</a>, <a class="closed ticket" href="https://code.djangoproject.com/ticket/2237" title="#2237: defect: Setting TEMPLATE_STRING_IF_INVALID causes admin page headline to vanish (closed: duplicate)">#2237</a> -- Modified variable resolution to allow template 'if' statements to work if TEMPLATE_STRING_IF_INVALID is set. Modified unit tests to force the use of this variable, so that returning <em> isn't confused with an actual failure.
</em></p>
TicketanonymousFri, 07 Jul 2006 19:25:14 GMTpriority, type, component, severity changed; version sethttps://code.djangoproject.com/ticket/1338#comment:6
https://code.djangoproject.com/ticket/1338#comment:6
<ul>
<li><strong>priority</strong>
changed from <em>normal</em> to <em>lowest</em>
</li>
<li><strong>type</strong>
changed from <em>defect</em> to <em>task</em>
</li>
<li><strong>version</strong>
set to <em>SVN</em>
</li>
<li><strong>component</strong>
changed from <em>Template system</em> to <em>Generic views</em>
</li>
<li><strong>severity</strong>
changed from <em>major</em> to <em>trivial</em>
</li>
</ul>
Ticket