Code

Opened 8 years ago

Closed 8 years ago

Last modified 8 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: russellm
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: UI/UX:

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.

Attachments (0)

Change History (6)

comment:1 Changed 8 years ago by HolgerSchurig

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 Changed 8 years ago by DanielTietze

  • Severity changed from normal to major

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 8 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 8 years ago by russellm

  • Owner changed from adrian to russellm

comment:5 Changed 8 years ago by russellm

  • Resolution set to fixed
  • Status changed from new to closed

(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 8 years ago by anonymous

  • Component changed from Template system to Generic views
  • priority changed from normal to lowest
  • Severity changed from major to trivial
  • Type changed from defect to task
  • Version set to SVN

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.