Opened 14 years ago

Closed 14 years ago

Last modified 14 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: master
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


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 Changed 14 years ago by HolgerSchurig

When I set

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

in my, 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 Changed 14 years ago by DanielTietze

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 Changed 14 years ago by django@…

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 Changed 14 years ago by Russell Keith-Magee

Owner: changed from Adrian Holovaty to Russell Keith-Magee

comment:5 Changed 14 years ago by Russell Keith-Magee

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 Changed 14 years ago by anonymous

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