Re: [Django] #34791: Prefetch's queryset attribute is ignored when the same nested relation is used multiple times.

58 views
Skip to first unread message

Django

unread,
Aug 24, 2023, 9:06:17 AM8/24/23
to django-...@googlegroups.com
#34791: Prefetch's queryset attribute is ignored when the same nested relation is
used multiple times.
-------------------------------------+-------------------------------------
Reporter: Maxime Toussaint | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 4.2
(models, ORM) |
Severity: Normal | Resolution:
Keywords: prefetch, | Triage Stage: Accepted
prefetch_related |
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Maxime Toussaint):

So, it makes sense that the order matters, especially for Prefetch with
to_attr, since until it has been fetched, it does not exist yet. Here
though, these are 2 very separate calls to the database that have
absolutely no interaction with each other. Shouldn't they be independent?
It doesn't make sense to me that it works in one order but it does not in
the other. I am vey surprised to hear that such a thing could be the
intended behaviour, as I can't make sense of why it could be. If you could
give more depth to your reasoning, it would be much appreciated.

--
Ticket URL: <https://code.djangoproject.com/ticket/34791#comment:9>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Aug 24, 2023, 1:19:28 PM8/24/23
to django-...@googlegroups.com
#34791: Prefetch's queryset attribute is ignored when the same nested relation is
used multiple times.
-------------------------------------+-------------------------------------
Reporter: Maxime Toussaint | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 4.2
(models, ORM) |
Severity: Normal | Resolution:
Keywords: prefetch, | Triage Stage: Accepted
prefetch_related |
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Mariusz Felisiak):

> I am vey surprised to hear that such a thing could be the intended
behaviour, as I can't make sense of why it could be. If you could give
more depth to your reasoning, it would be much appreciated.

I changed my mind and agreed that we should fix it, that's why I accepted
this ticket.

--
Ticket URL: <https://code.djangoproject.com/ticket/34791#comment:10>

Django

unread,
Aug 29, 2023, 10:21:26 AM8/29/23
to django-...@googlegroups.com
#34791: Prefetch's queryset attribute is ignored when the same nested relation is
used multiple times.
-------------------------------------+-------------------------------------
Reporter: Maxime Toussaint | Owner: Maxime
| Toussaint
Type: Bug | Status: assigned

Component: Database layer | Version: 4.2
(models, ORM) |
Severity: Normal | Resolution:
Keywords: prefetch, | Triage Stage: Accepted
prefetch_related |
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Maxime Toussaint):

* owner: nobody => Maxime Toussaint
* status: new => assigned


--
Ticket URL: <https://code.djangoproject.com/ticket/34791#comment:11>

Django

unread,
Aug 29, 2023, 11:26:59 AM8/29/23
to django-...@googlegroups.com
#34791: Prefetch's queryset attribute is ignored when the same nested relation is
used multiple times.
-------------------------------------+-------------------------------------
Reporter: Maxime Toussaint | Owner: Maxime
| Toussaint
Type: Bug | Status: assigned
Component: Database layer | Version: 4.2
(models, ORM) |
Severity: Normal | Resolution:
Keywords: prefetch, | Triage Stage: Accepted
prefetch_related |
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Maxime Toussaint):

* has_patch: 0 => 1


Comment:

https://github.com/django/django/pull/17207

--
Ticket URL: <https://code.djangoproject.com/ticket/34791#comment:12>

Django

unread,
Sep 7, 2023, 7:13:11 AM9/7/23
to django-...@googlegroups.com
#34791: Prefetch's queryset attribute is ignored when the same nested relation is
used multiple times.
-------------------------------------+-------------------------------------
Reporter: Maxime Toussaint | Owner: Maxime
| Toussaint
Type: Bug | Status: assigned
Component: Database layer | Version: 4.2
(models, ORM) |
Severity: Normal | Resolution:
Keywords: prefetch, | Triage Stage: Ready for
prefetch_related | checkin

Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* stage: Accepted => Ready for checkin


--
Ticket URL: <https://code.djangoproject.com/ticket/34791#comment:13>

Django

unread,
Sep 7, 2023, 7:59:38 AM9/7/23
to django-...@googlegroups.com
#34791: Prefetch's queryset attribute is ignored when the same nested relation is
used multiple times.
-------------------------------------+-------------------------------------
Reporter: Maxime Toussaint | Owner: Maxime
| Toussaint
Type: Bug | Status: closed

Component: Database layer | Version: 4.2
(models, ORM) |
Severity: Normal | Resolution: fixed

Keywords: prefetch, | Triage Stage: Ready for
prefetch_related | checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak <felisiak.mariusz@…>):

* status: assigned => closed
* resolution: => fixed


Comment:

In [changeset:"254df3a3bbc2f4df51f9e2070ab2e214553f67d0" 254df3a]:
{{{
#!CommitTicketReference repository=""
revision="254df3a3bbc2f4df51f9e2070ab2e214553f67d0"
Fixed #34791 -- Fixed incorrect Prefetch()'s cache for singly related
objects.

Changed the cache name used for singly related objects to be the
to_attr parameter passed to a Prefetch object. This fixes issues with
checking if values have already been fetched in cases where the Field
already has some prefetched value, but not for the same model attr.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/34791#comment:14>

Reply all
Reply to author
Forward
0 new messages