#34358: qs.filter(Exact(expr, value)) doesn’t work
-------------------------------------+-------------------------------------
Reporter: Roman | Owner: nobody
Odaisky |
Type: Bug | Status: new
Component: Database | Version: 4.1
layer (models, ORM) |
Severity: Normal | Keywords:
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
{{{
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?
--
Ticket URL: <https://code.djangoproject.com/ticket/34358>
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 view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/01070186715afbe5-35264bec-682b-4b47-aae5-b5414bdfe01a-000000%40eu-central-1.amazonses.com.