#28549: Can't defer() fields from super- and sub-class at the same time
-----------------------------------------+------------------------
Reporter: Jeremy Kerr | Owner: nobody
Type: Uncategorized | Status: new
Component: Uncategorized | Version: 1.11
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-----------------------------------------+------------------------
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.
--
Ticket URL: <https://code.djangoproject.com/ticket/28549>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/052.168e419f997d986a6b304b39d168f517%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.