﻿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
20923	Unable to use fields from prefetch_related() in only() and defer()	alexpirine	nobody	"If I run the following query, I get the same error as seen in #14694:

{{{
ParentModel.objects.prefetch_related('child_model').only('parent_attribute', 'childs__child_atrtibute').all()
}}}

I guess it is not really a bug, as using `only()` and `defer()` in combination with `prefetch_related()` is not documented (documentation only mentions the use of `select_related()` with `defer()`).

But it could be a useful feature: is there a reason to support `select_related()` but not `prefetch_related()`?

I hope that an improvement of the patch for #14694 can enable this feature.

P.S. I wasn't able to fix it by myself, due to my lack of understanding of how `django.db.models.sql.query.deferred_to_data()` works. Simply removing `and field.field.unique` in `django.db.models.sql.query.is_reverse_o2o()` makes the error message disappear, but the instructions in `only()` remain ignored."	New feature	closed	Database layer (models, ORM)	1.5	Normal	wontfix	defer only ForeignKey reverse relationship	as@…	Unreviewed	0	0	0	0	0	0
