My use case is the following:
- Annotate a queryset with the count of reverse FKs, matching a condition
This works fine given a many-to-one relationship, however not with many-
to-one/none.
With the many-to-one/none, it appears an INNER JOIN is made, which removes
objects from my queryset which an empty reverse FK set.
To summarize:
Expected:
Annotate all objects with the a count of reverse FKs matching a condition
Actual:
Annotate only objects objects with 1 or more associated reverse FKs, with
a count of the reverse FKs matching a condition
--
Ticket URL: <https://code.djangoproject.com/ticket/24753>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0
Comment:
I've added a unit test which demonstrates the issue here:
https://github.com/django/django/pull/4613
--
Ticket URL: <https://code.djangoproject.com/ticket/24753#comment:1>
Comment (by akaariai):
I have a guess what could be happening here. The ORM generates joins as
INNER JOINs when using build_filter(). We should manually promote those
joins to OUTER JOINs afterwards. Can't work on this today, so I'll check
this tomorrow.
--
Ticket URL: <https://code.djangoproject.com/ticket/24753#comment:2>
* severity: Normal => Release blocker
* stage: Unreviewed => Accepted
--
Ticket URL: <https://code.djangoproject.com/ticket/24753#comment:3>
Comment (by shaib):
See also #24766, similar problems with non-aggregating annotations.
--
Ticket URL: <https://code.djangoproject.com/ticket/24753#comment:4>
* status: new => closed
* resolution: => duplicate
Comment:
The proposed test is similar to the one added with the fix for #24766 and
now passes.
--
Ticket URL: <https://code.djangoproject.com/ticket/24753#comment:5>