﻿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
10710	Invalid results with only() when model has two foreign keys to other models that inherit from a single abstract parent	mrts	nobody	"Given the models:

{{{
from django.db import models

class Base(models.Model):
    name = models.CharField(max_length=10)
    lots_of_text = models.TextField()

    class Meta:
        abstract = True

    def __unicode__(self):
        return self.name

class A(Base):
    a_field = models.CharField(max_length=10)

class B(Base):
    b_field = models.CharField(max_length=10)

class C(Base):
    a = models.ForeignKey(A)
    b = models.ForeignKey(B)
    is_published = models.BooleanField()
}}}

the following occurs:

{{{
# all ok here:
>>> from somewhere.models import A, B, C
>>> results = C.objects.all().select_related()
>>> results[0].a.id
2
>>> results[0].a.lots_of_text
u'Sed ut perspiciatis unde omnis iste natus error...'

# bizarre things happen: `id` and `lots_of_text` are swapped
>>> results = C.objects.all().only('name', 'a', 'b').select_related()
>>> results[0].a.lots_of_text
2
>>> results[0].a.id
u'Sed ut perspiciatis unde omnis iste natus error...'

# no luck in deferring two relations with only():
>>> C.objects.all().only('name', 'a', 'b').select_related().only('a__name', 'b__name')
Traceback (most recent call last):
...
FieldDoesNotExist: A has no field named 'b'

# deferring a single relation with only works:
>>> C.objects.all().only('name', 'a', 'b').select_related().only('a__name')
[<C_Deferred_b_is_published_lots_of_text_name: c1>, ...]
}}}"		closed	Database layer (models, ORM)	dev		fixed	defer only, efficient-admin		Unreviewed	0	0	0	0	0	0
