Changes between Initial Version and Version 1 of Ticket #24642
- Timestamp:
- Apr 14, 2015, 9:47:46 AM (10 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
Ticket #24642 – Description
initial v1 1 1 If you generate a query set like: 2 [[BR]] 2 {{{ 3 3 orders = Order.objects.filter( date = paramDate, objfilter = paramObjfilter ).order_by( 'date' ) 4 4 dudes = orders.values('dude').distinct().exclude(dude__isnull = True) 5 [[BR]] 6 [[BR]] 5 }}} 7 6 8 7 Query will be: 9 [[BR]] 8 {{{ 10 9 SELECT DISTINCT "base_ordentrabajo"."dude_id", "base_orders"."date" FROM "base_orders" WHERE ... 11 [[BR]] 10 }}} 12 11 If you remove order_by and make distinct after query is quite different (and like should be) 13 [[BR]] 12 {{{ 14 13 orders = Order.objects.filter( date = paramDate, objfilter = paramObjfilter ) 15 14 dudes = orders.values('dude').distinct().exclude(dude__isnull = True) 16 [[BR]] 15 17 16 SELECT DISTINCT "base_ordentrabajo"."dude_id" FROM "base_orders" WHERE ... 18 [[BR]] 17 }}} 19 18 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)