#12554: silent_variable_failure not suppressing exception during dict lookup
---------------------------------------------------------+------------------
          Reporter:  Thomas Steinacher <[email protected]>  |         Owner:  
nobody
            Status:  new                                 |     Milestone:  1.2  
 
         Component:  Template system                     |       Version:  SVN  
 
        Resolution:                                      |      Keywords:       
 
             Stage:  Accepted                            |     Has_patch:  1    
 
        Needs_docs:  0                                   |   Needs_tests:  0    
 
Needs_better_patch:  1                                   |  
---------------------------------------------------------+------------------
Comment (by [email protected]):

 I realized I wasn't working from the trunk. Here is a real proposed patch:
 {{{
 ===================================================================
 --- __init__.py (revision 12610)
 +++ __init__.py (working copy)
 @@ -583,7 +583,24 @@
                  if not lookup:
                      arg_vals.append(mark_safe(arg))
                  else:
 -                    arg_vals.append(arg.resolve(context))
 +                    #arg_vals.append(arg.resolve(context))
 +                    try:
 +                        arg_val = arg.resolve(context)
 +                    except VariableDoesNotExist:
 +                        if ignore_failures:
 +                            arg_val = None
 +                        else:
 +                            if settings.TEMPLATE_STRING_IF_INVALID:
 +                                global invalid_var_format_string
 +                                if invalid_var_format_string is None:
 +                                    invalid_var_format_string = '%s' in
 settings.TEMPLATE_STRING_IF_INVALID
 +                                if invalid_var_format_string:
 +                                    arg_val=
 settings.TEMPLATE_STRING_IF_INVALID % self.var
 +                                else:
 +                                    arg_val=
 settings.TEMPLATE_STRING_IF_INVALID
 +                            else:
 +                                arg_val =
 settings.TEMPLATE_STRING_IF_INVALID
 +                    arg_vals.append(arg_val)
              if getattr(func, 'needs_autoescape', False):

 Here is a test case:
 >>> from django.template import Context, Template
 >>> t = Template("{{'test'|default:notreal}}")
 >>> t.render(Context())
 Traceback (most recent call last):
   File "<console>", line 1, in <module>
   File
 "/opt/local/OnQueue2/OQTools/pythonlib/trunk/django/template/__init__.py",
 line 184, in render
     return self._render(context)
   File
 "/opt/local/OnQueue2/OQTools/pythonlib/trunk/django/template/__init__.py",
 line 178, in _render
     return self.nodelist.render(context)
   File
 "/opt/local/OnQueue2/OQTools/pythonlib/trunk/django/template/__init__.py",
 line 799, in render
     bits.append(self.render_node(node, context))
   File
 "/opt/local/OnQueue2/OQTools/pythonlib/trunk/django/template/debug.py",
 line 82, in render_node
     raise wrapped
 TemplateSyntaxError: Caught an exception while rendering: Failed lookup
 for key [notreal] in u'[{}]'

 }}}

-- 
Ticket URL: <http://code.djangoproject.com/ticket/12554#comment:3>
Django <http://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 post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.

Reply via email to