#24642: If queryset has orderby before distinct query selects the orderby
----------------------------------------------+--------------------
     Reporter:  ark4n631                      |      Owner:  nobody
         Type:  Bug                           |     Status:  new
    Component:  Database layer (models, ORM)  |    Version:  1.7
     Severity:  Normal                        |   Keywords:
 Triage Stage:  Unreviewed                    |  Has patch:  0
Easy pickings:  0                             |      UI/UX:  0
----------------------------------------------+--------------------
 If you generate a query set like:
 [[BR]]
 orders = Order.objects.filter( date = paramDate, objfilter =
 paramObjfilter ).order_by( 'date' )
 dudes  = orders.values('dude').distinct().exclude(dude__isnull = True)
 [[BR]]
 [[BR]]

 Query will be:
 [[BR]]
 SELECT DISTINCT "base_ordentrabajo"."dude_id", "base_orders"."date" FROM
 "base_orders" WHERE ...
 [[BR]]
 If you remove order_by and make distinct after query is quite different
 (and like should be)
 [[BR]]
 orders = Order.objects.filter( date = paramDate, objfilter =
 paramObjfilter )
 dudes  = orders.values('dude').distinct().exclude(dude__isnull = True)
 [[BR]]
 SELECT DISTINCT "base_ordentrabajo"."dude_id" FROM "base_orders" WHERE ...
 [[BR]]
 So i can't make an order_by if i need to make a distinct first. Anyway
 django should warn of query.order_by or don't allow to make a subset query
 filter with distinct if you order in the first place because this lead to
 unexpected results on query (query will contain not distinct values for
 the field you are searching for because it adds the order_by field value
 to the query)

--
Ticket URL: <https://code.djangoproject.com/ticket/24642>
Django <https://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 unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/051.2ff07b3c4e4b6b26a595e8fd9175d91b%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to