Changes between Initial Version and Version 1 of Ticket #24642


Ignore:
Timestamp:
Apr 14, 2015, 9:47:46 AM (10 years ago)
Author:
Tim Graham
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #24642 – Description

    initial v1  
    11If you generate a query set like:
    2 [[BR]]
     2{{{
    33orders = Order.objects.filter( date = paramDate, objfilter = paramObjfilter ).order_by( 'date' )
    44dudes  = orders.values('dude').distinct().exclude(dude__isnull = True)
    5 [[BR]]
    6 [[BR]]
     5}}}
    76
    87Query will be:
    9 [[BR]]
     8{{{
    109SELECT DISTINCT "base_ordentrabajo"."dude_id", "base_orders"."date" FROM "base_orders" WHERE ...
    11 [[BR]]
     10}}}
    1211If you remove order_by and make distinct after query is quite different (and like should be)
    13 [[BR]]
     12{{{
    1413orders = Order.objects.filter( date = paramDate, objfilter = paramObjfilter )
    1514dudes  = orders.values('dude').distinct().exclude(dude__isnull = True)
    16 [[BR]]
     15
    1716SELECT DISTINCT "base_ordentrabajo"."dude_id" FROM "base_orders" WHERE ...
    18 [[BR]]
     17}}}
    1918So 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)
Back to Top