#35677: Unexpected behaviour of Prefetch with queryset filtering on a through
model
-------------------------------------+-------------------------------------
Reporter: David Glenck | Owner: (none)
Type: Bug | Status: new
Component: Database layer | Version: 5.1
(models, ORM) |
Severity: Normal | Resolution:
Keywords: Prefetch, | Triage Stage: Accepted
prefetch_related, many-to-many |
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Simon Charette):
Thanks Natalia, #27303 is effectively a manifestation of this problem in
the admin. We don't have a good way to denote that joins against multi-
valued relationships should be reused between different `QuerySet` method
calls. It's a problem we hacked around for `filter` with this ''sticky''
notion but the problem exists for `annotate` and any other ORM method that
allows for multi-valued (many-to-many or reverse one-to-many). I believe
there are other tickets that discussed a generic way to alias such
relationships so they are always reusable, I know it was brought up during
the design of `FilteredRelation` for sure.
IIRC the design was something along the lines of
{{{#!python
Subscriber.objects.alias(
# Force the reuse of all JOINs up to Susbcription (including Status)
subscriptions=Relation("subscriptions", reuse=True),
).filter(subscriber=subscriber).filter(status__is_active=True)
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/35677#comment:7>
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/01070191569603ca-05723ce6-69a2-41ec-b503-3cbe17105c3f-000000%40eu-central-1.amazonses.com.