﻿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
32704	QuerySet.defer() doesn't clear deferred field when chaining with only().	Manuel Baclet	David Wobrock	"Considering a simple `Company` model with four fields: `id`, `name`, `trade_number` and `country`. If we evaluate a queryset containing a `.defer()` following a `.only()`, the generated sql query selects unexpected fields. For example: 

{{{#!python
Company.objects.only(""name"").defer(""name"")
}}}
loads all the fields with the following query:
{{{#!sql
SELECT ""company"".""id"", ""company"".""name"", ""company"".""trade_number"", ""company"".""country"" FROM ""company""
}}}

and 

{{{#!python
Company.objects.only(""name"").defer(""name"").defer(""country"")
}}}
also loads all the fields with the same query:
{{{#!sql
SELECT ""company"".""id"", ""company"".""name"", ""company"".""trade_number"", ""company"".""country"" FROM ""company""
}}}

In those two cases, i would expect the sql query to be:
{{{#!sql
SELECT ""company"".""id"" FROM ""company""
}}}

In the following example, we get the expected behavior:
{{{#!python
Company.objects.only(""name"", ""country"").defer(""name"")
}}}
only loads ""id"" and ""country"" fields with the following query:
{{{#!sql
SELECT ""company"".""id"", ""company"".""country"" FROM ""company"" 
}}}"	Bug	closed	Database layer (models, ORM)	3.1	Normal	fixed	defer only	Manuel Baclet David Wobrock	Accepted	1	0	0	0	0	0
