Opened 19 years ago

Closed 18 years ago

Last modified 18 years ago

#1338 closed task (fixed)

Undefined context variables should not resolve to the value of TEMPLATE_STRING_IF_INVALID

Reported by: django@… Owned by: Russell Keith-Magee
Component: Generic views Version: dev
Severity: trivial Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

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 FilterExpression is passing the
TEMPLATE_STRING_IF_INVALID value through the filters, which is probably not going to fit with user expectations.

Perhaps resolve_variable should be consistently raising an exception
for all unresolvable variables and Node renderers and FilterExpression 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.

Change History (6)

comment:1 by HolgerSchurig, 18 years ago

When I set

  #TEMPLATE_STRING_IF_INVALID = "...missing..."

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.

I think this is related to this bug.

comment:2 by DanielTietze, 18 years ago

Severity: normalmajor

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.

comment:3 by django@…, 18 years ago

Just a note that this is one of the things I fixed in #1400 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.

comment:4 by Russell Keith-Magee, 18 years ago

Owner: changed from Adrian Holovaty to Russell Keith-Magee

comment:5 by Russell Keith-Magee, 18 years ago

Resolution: fixed
Status: newclosed

(In [3268]) Fixes #1338, Refs #1400, #2237 -- 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 isn't confused with an actual failure.

comment:6 by anonymous, 18 years ago

Component: Template systemGeneric views
priority: normallowest
Severity: majortrivial
Type: defecttask
Version: SVN
Note: See TracTickets for help on using tickets.
Back to Top