﻿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
28549	Can't defer() fields from super- and sub-class at the same time	Jeremy Kerr	Jeremy Kerr	"Using the models:

{{{#!python
from django.db import models

class Base(models.Model):
    f1 = models.CharField(max_length=10)

class Sub(Base):
    f2 = models.CharField(max_length=10)
}}}

it seems that I can't `defer()` both `f1` and `f2` in a single query:

{{{
>>> Sub.objects.defer('f1', 'f2').query.sql_with_params()[0]
u'SELECT ""defer_base"".""id"", ""defer_base"".""f1"", ""defer_sub"".""base_ptr_id"" FROM ""defer_sub"" INNER JOIN ""defer_base"" ON (""defer_sub"".""base_ptr_id"" = ""defer_base"".""id"")'
}}}

(we're seeing `f1` in the SELECT value list).

I seem to be able to defer `f1` or `f2` separately though.

I'm no django hacker, but: it seems as though `django.db.models.sql.query.Query.deferred_to_data()` is iterating both models in the loop:

{{{#!python
#640:
            for model, values in six.iteritems(seen):
                for field in model._meta.fields:
                    if field in values:
                        continue
}}}

^^- and so is discovering `f1` twice: once as `Base.f1` and again as `Sub.f1`. Since the `field in values` test only skips `Base.f1`, we're still left with `Sub.f1` in the `workset` dict.
"	Bug	closed	Database layer (models, ORM)	dev	Normal	fixed		Jeremy Kerr Simon Charette	Accepted	1	0	0	0	0	0
