Russell Keith-Magee wrote: > > On 31/03/2008, at 2:33 AM, mtrier wrote: > >> Before opening a ticket I thought I would check what the expected >> behavior is for generative values(). This is the behavior I'm seeing >> on Queryset Refactor branch and to me it seems like it is not the >> correct behavior. >> >>>>> from original.foo.models import Category >>>>> Category.objects.all() >> [<Category: Algol>, <Category: Smalltalk>, <Category: PHP>, <Category: >> CSharp>] >>>>> Category.objects.values('name') >> [{'name': u'Algol'}, {'name': u'Smalltalk'}, {'name': u'PHP'}, >> {'name': u'CSharp'}] >>>>> Category.objects.values('name', 'id') >> [{'name': u'Algol', 'id': 1}, {'name': u'Smalltalk', 'id': 2}, >> {'name': u'PHP', 'id': 3}, {'name': u'CSharp', 'id': 4}] >>>>> Category.objects.values('name').values('id') >> [{'name': u'Algol'}, {'name': u'Smalltalk'}, {'name': u'PHP'}, >> {'name': u'CSharp'}] >> >> It would seem to me that the last query should return the same thing >> as the prior one. > > Agreed. This looks like a bug to me; at a guess, the problem will be > that when ValuesQuerySet is cloned, it doesn't copy the attribute list.
I also agree that this is a bug, as the "first one wins" behavior displayed above is not intuitive. But what should the desired behavior should be? The OP suggests an additive behavior similar to the way filter() operates. However, there is also the option of a "last one wins" approach, as seen by the order_by() method (on trunk, is it the same in qs-rf?): >>> User.objects.order_by('last_name')._order_by ('last_name',) >>> User.objects.order_by('last_name').order_by('first_name')._order_by ('first_name',) >>> User.objects.order_by('last_name', 'first_name')._order_by ('last_name', 'first_name') If I had to pick a behavior, I guess I would lean towards the "last one wins" approach. order_by() and values() are methods that I typically use towards the end of my QuerySet constructions, and if I'm passed a QuerySet from some other code I would like my order_by() or values() to take precedence. Gary --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django developers" group. To post to this group, send email to django-developers@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-developers?hl=en -~----------~----~----~----~------~----~------~--~---