1
0
mirror of https://github.com/django/django.git synced 2025-10-24 06:06:09 +00:00

[5.2.x] Fixed #35677 -- Avoided non-sticky filtering of prefetched many-to-many.

The original queryset._next_is_sticky() call never had the intended effect as
no further filtering was applied internally after the pk__in lookup making it
a noop.

In order to be coherent with how related filters are applied when retrieving
objects from a related manager the effects of what calling _next_is_sticky()
prior to applying annotations and filters to the queryset provided for
prefetching are emulated by allowing the reuse of all pre-existing JOINs.

Thanks David Glenck and Thiago Bellini Ribeiro for the detailed reports and
tests.

Backport of 2598b371a9 from main.
This commit is contained in:
Simon Charette
2025-01-14 06:18:30 +01:00
committed by Sarah Boyce
parent d57bf4618c
commit 8aea6b802c
4 changed files with 55 additions and 7 deletions

View File

@@ -35,6 +35,7 @@ class FavoriteAuthors(models.Model):
likes_author = models.ForeignKey(
Author, models.CASCADE, to_field="name", related_name="likes_me"
)
is_active = models.BooleanField(default=True)
class Meta:
ordering = ["id"]