﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
32089	prefetch_related_objects() does not work for reused model instances.	Dennis Kliban	AlexeyNigin	"Our project processes instances in a stream. In some cases the instances are repeated. In these cases, we discovered that `prefetch_related_objects()` does not set the `to_attr` on all of the instances if the first instance in the list already has it set.

When Django determines that the very first instance in the list `is_fetched`[0], it does not call into the the `prefetch_one_level()`[1]. The attributed specified in the to_attr parameter is only set in the `prefetch_one_level()` method[2].

`is_fetched` is set by looking for the `to_attr` attribute on the instance[3].

[0] https://github.com/django/django/blob/stable/2.2.x/django/db/models/query.py#L1605-L1609
[1] https://github.com/django/django/blob/stable/2.2.x/django/db/models/query.py#L1624
[2] https://github.com/django/django/blob/stable/2.2.x/django/db/models/query.py#L1799
[3] https://github.com/django/django/blob/stable/2.2.x/django/db/models/query.py#L1708"	Bug	closed	Database layer (models, ORM)	2.2	Normal	fixed		François Freitag Adam Johnson	Ready for checkin	1	0	0	0	0	0
