﻿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
27535	RFE: Exclude pk from queries	Alexander Todorov	nobody	"Hello guys,
in `models/sql/query.py` there is this snippet:

{{{
   def deferred_to_data(self, target, callback):
       ... skip ...
       must_include = {orig_opts.concrete_model: {orig_opts.pk}}
}}}

introduced in https://github.com/django/django/commit/29050ef999e1931efb6c62471c7e07d2ea5e96ea, which is causing the following difference between queries:

{{{
>>> print(Book.objects.values('genre').query)
SELECT ""demoproject_book"".""genre_id"" FROM ""demoproject_book""
>>>
}}}

is different from

{{{
>>> print(Book.objects.only('genre').query)
SELECT ""demoproject_book"".""id"", ""demoproject_book"".""genre_id"" FROM ""demoproject_book""
}}}

Because the ""id"" field is included in the second query it produces different values when .annotate()-ed.

In the environment I work with I don't want to use .values() b/c when I iterate over the results I need to have the objects, not a dict of values.  I'm requesting a method for excluding the PK field from the query. Alternatively I'd like for the .values() method to have an alternative which returns model objects, not dictionary. 

Can you point me in the right direction? I'm willing to provide a patch. 



"	New feature	closed	Database layer (models, ORM)	1.10	Normal	wontfix			Unreviewed	0	0	0	0	0	0
