﻿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
34358	qs.filter(Exact(expr, value)) doesn’t work on aggregations.	Roman Odaisky	nobody	"{{{
class Child(Model):
    parent = ForeignKey(Parent)

a = Parent.objects.filter(Exact(Count(""child""), 0)).count()
b = Parent.objects.annotate(n=Count(""child"")).filter(n=0).count()
}}}
Expected: a == b == <number of childless parents>
Actual: a is always 0, b is correct

The two result in different SQL:
{{{
-- a:
SELECT COUNT(*) AS ""__count""
FROM ""parent"" LEFT OUTER JOIN ""child"" ON (""parent"".""id"" = ""child"".""report_id"")
HAVING COUNT(""child"".""id"") = 0

-- b:
SELECT COUNT(*)
FROM (
    SELECT COUNT(""child"".""id"") AS ""n""
    FROM ""parent"" LEFT OUTER JOIN ""child"" ON (""parent"".""id"" = ""child"".""parent_id"")
    GROUP BY ""parent"".""id""
    HAVING COUNT(""child"".""id"") = 0
)
}}}
Am I correct in assuming A should have worked as well?"	Bug	closed	Database layer (models, ORM)	4.1	Normal	fixed			Unreviewed	0	0	0	0	0	0
