#8462: template tag Length and the 'error'
-----------------------------+----------------------------------------------
 Reporter:  magneto          |       Owner:  nobody    
   Status:  new              |   Milestone:            
Component:  Template system  |     Version:  SVN       
 Keywords:  length           |       Stage:  Unreviewed
Has_patch:  0                |  
-----------------------------+----------------------------------------------
 django/template/defaultfilters.py", line 469, in length

 if the input object has no __len__ defined, this throws a nasty exception
 .. given the very large number of time i imagine this is used

 would it be proper to simply 'return 0' for non list like things?

 in particular the 'with' command is problematic (if 'my_thing' is
 unresolved, it blows up)
 {{{
 {% with my_thing|length as my_length %}

 {% endwith %}
 }}}

 {{{
 Index: django/template/defaultfilters.py
 ===================================================================
 --- django/template/defaultfilters.py   (revision 8455)
 +++ django/template/defaultfilters.py   (working copy)
 @@ -466,7 +466,10 @@

  def length(value):
      """Returns the length of the value - useful for lists."""
 -    return len(value)
 +    try:
 +        return len(value)
 +    except:
 +        return 0
  length.is_safe = True

  def length_is(value, arg):

 }}}

-- 
Ticket URL: <http://code.djangoproject.com/ticket/8462>
Django Code <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