> Interestingly enough, just doing a .filter(m2m_relation__foo='bar') might
change the results

Is that not because it's a filter? Would ".
annotate(x=F('m2m_relation__foo'))" change the results in any way? Sorry if
I'm not following.



On 21 Aug 2017 06:58, "Anssi Kääriäinen" <akaar...@gmail.com> wrote:

On Sunday, August 20, 2017 at 2:48:23 AM UTC+3, Josh Smeaton wrote:

> Thanks for making me elaborate, because I'm probably wrong. I'll step
> through what my thinking was though.
>
> '.annotate(local=F('related__field'))' will join to the related table. If
> `related` is a nullable foreign key, then a join would do an implicit
> filter, removing the row from the result set if it had no relation, and
> reducing the count.
>
> But Django models a nullable foreign key join as a LEFT JOIN which
> wouldn't filter the row out and wouldn't reduce the count.
>
> Multivalue relationships (reverse foreign key and m2m joins) would need
> some care though I think. I'm not sure if the same annotation above works
> on m2m joins or not.
>

Interestingly enough, just doing a .filter(m2m_relation__foo='bar') might
change the results. For m2m relations, any non-aggregate annotation is not
safe to remove.

I believe our test cases are not fully covering here, so removing the
annotations will be a bit risky. If there are cases where removal is known
to be safe, it's of course a good idea to remove anything extra from the
query.

 - Anssi

-- 
You received this message because you are subscribed to the Google Groups
"Django developers (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to django-developers+unsubscr...@googlegroups.com.
To post to this group, send email to django-developers@googlegroups.com.
Visit this group at https://groups.google.com/group/django-developers.
To view this discussion on the web visit https://groups.google.com/d/
msgid/django-developers/51a5c1ad-e071-482b-aa3a-184dd4145413%40googlegroups.
com
<https://groups.google.com/d/msgid/django-developers/51a5c1ad-e071-482b-aa3a-184dd4145413%40googlegroups.com?utm_medium=email&utm_source=footer>
.

For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers  (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-developers+unsubscr...@googlegroups.com.
To post to this group, send email to django-developers@googlegroups.com.
Visit this group at https://groups.google.com/group/django-developers.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-developers/CAFNZOJNfBAw5HzzT%2BZTZcYxTRTWSFBPSM%3DHSQ%3Dh4HBUK71JUwg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to