﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
30130	Django .values().distinct() returns a lot more records than .values().distinct().count()	James Lin	nobody	"I have a table virtualmachineresources, which has 100k+ rows, it has columns 'machine` and `cluster`, some rows the cluster field is empty. it has repeating rows of machine + with/without cluster, hence I want to use the distinct() method.

using .values().distinct().count(), it return 2k rows


{{{
In [6]: VirtualMachineResources.objects.all().values('machine', 'cluster')
   ...: .distinct().count()                                               
Out[6]: 2247
}}}


When I loop through the distinct query 

{{{
for resource in VirtualMachineResources.objects.all().values('machine', 'cluster').distinct(): 
    print(resource['machine'], resource['cluster'])
}}}


I observed it return 100k rows, with repeating rows that the same 'machine` with/without the cluster.

Here is the corresponding stackoverflow question https://stackoverflow.com/questions/54354462/django-distinct-returns-more-records-than-count"	Bug	new	Database layer (models, ORM)	2.1	Normal				Unreviewed	0	0	0	0	0	0
