Re: [Django] #32089: prefetch_related_objects() does not work for reused model instances.

7 views
Skip to first unread message

Django

unread,
Oct 15, 2020, 1:07:38 PM10/15/20
to django-...@googlegroups.com
#32089: prefetch_related_objects() does not work for reused model instances.
-------------------------------------+-------------------------------------
Reporter: Dennis Kliban | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 2.2
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Adam (Chainz) Johnson):

I had a brief look at fixing this. I think it's possible by filtering the
objects before trying to prefetch for them. See
https://github.com/adamchainz/django/commit/bc2991c0908abbf4973cbb4850ffff0dea4bbd6f
. This currently fails three prefetch tests - one for executing an extra
query, two for executing one fewer query (which may actually represent a
true optimization).

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

Django

unread,
Nov 10, 2020, 9:02:23 PM11/10/20
to django-...@googlegroups.com
#32089: prefetch_related_objects() does not work for reused model instances.
-------------------------------------+-------------------------------------
Reporter: Dennis Kliban | Owner:
| AlexeyNigin
Type: Bug | Status: assigned

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

* owner: nobody => AlexeyNigin
* status: new => assigned


Comment:

Hello! I would like to work on this ticket to complete a requirement for
the final project in my software engineering class
(https://web.eecs.umich.edu/~weimerw/481/hw6.html). Since this is my first
time contributing to Django, it might take me some time to make progress
on this ticket. Thank you for your patience, and if you need to fix this
ticket urgently in the meantime, feel free to unassign me from it.

--
Ticket URL: <https://code.djangoproject.com/ticket/32089#comment:8>

Django

unread,
Dec 14, 2020, 1:34:47 AM12/14/20
to django-...@googlegroups.com
#32089: prefetch_related_objects() does not work for reused model instances.
-------------------------------------+-------------------------------------
Reporter: Dennis Kliban | Owner:
| AlexeyNigin
Type: Bug | Status: assigned
Component: Database layer | Version: 2.2
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

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

* has_patch: 0 => 1


Comment:

PR: https://github.com/django/django/pull/13774

I modified Adam Johnson's patch so that it doesn't fail any of the
prefetch tests, and added a minimized version of Dennis Kliban's test for
regression. Would appreciate a review!

--
Ticket URL: <https://code.djangoproject.com/ticket/32089#comment:9>

Django

unread,
Dec 16, 2020, 4:59:37 AM12/16/20
to django-...@googlegroups.com
#32089: prefetch_related_objects() does not work for reused model instances.
-------------------------------------+-------------------------------------
Reporter: Dennis Kliban | Owner:
| AlexeyNigin
Type: Bug | Status: assigned
Component: Database layer | Version: 2.2
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Ready for
| 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/32089#comment:10>

Django

unread,
Dec 16, 2020, 2:59:50 PM12/16/20
to django-...@googlegroups.com
#32089: prefetch_related_objects() does not work for reused model instances.
-------------------------------------+-------------------------------------
Reporter: Dennis Kliban | Owner:
| AlexeyNigin
Type: Bug | Status: closed

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

Keywords: | Triage Stage: Ready for
| 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:"b9ba85a7ce582f4821a21119a6c130dacab496c4" b9ba85a]:
{{{
#!CommitTicketReference repository=""
revision="b9ba85a7ce582f4821a21119a6c130dacab496c4"
Fixed #32089 -- Fixed prefetch_related_objects() when some objects are
already fetched.

Thanks Dennis Kliban for the report and Adam Johnson for the initial
patch.

Co-authored-by: Adam Johnson <m...@adamj.eu>
}}}

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

Reply all
Reply to author
Forward
0 new messages