#12549: Native list method sort() does not work on ValuesListQuerySet instance
returned from value_list()  QuerySet
----------------------------+-----------------------------------------------
 Reporter:  jonathan_livni  |       Owner:  nobody    
   Status:  new             |   Milestone:            
Component:  Core framework  |     Version:  1.1-beta-1
 Keywords:                  |       Stage:  Unreviewed
Has_patch:  0               |  
----------------------------+-----------------------------------------------
 '''The following code causes an exception:'''


 {{{
     members = Member.objects.all().values_list('name',flat=True)
     members.sort(key=len,reverse=True)  # Sorts members so that longer
 strings are first
 }}}

 '''The exception is:'''


 {{{
    Traceback (most recent call last):
      File "members_update.py", line 1179, in <module>
     uploadMembers(trace,mems.members,configuration=conf)
      File "/usr/lib/python2.5/site-packages/django/db/transaction.py",
 line 265, in _commit_manually
     return func(*args, **kw)
      File "members_update.py", line 186, in uploadProducts
     members.sort(key=len,reverse=True)  # Sorts members so that longer
 strings are first
    AttributeError: 'ValuesListQuerySet' object has no attribute 'sort'
 }}}


 As far as the documentation goes, value_list() QuerySet was supposed to
 return a List object, not a ValuesListQuerySet. The documentation
 specifically states that value_list does is one of the functions not
 returning a QuerySet. Even if there's some kind of need to to return a
 List object, at least you would expect it to behave like a List object and
 support its methods - such as sort()

-- 
Ticket URL: <http://code.djangoproject.com/ticket/12549>
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 django-upda...@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.


Reply via email to