﻿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
19870	select_related has issues with models linked by a FK which inherit from a common model	loic84	nobody	"Considering the following models:

{{{
class Fowl(models.Model):
    name = models.CharField(max_length=10)

class Hen(Fowl):
    pass

class Chick(Fowl):
    mother = models.ForeignKey(Hen)
}}}

`Chick.objects.select_related()[0].mother` would return a `Hen` model instance, but the value of its fields inherited from `Fowl` would be set to the value of the fields of the queried `Chick`.

The issue lies somewhere in the query generation as I tried the generated query in an SQL shell and it indeed pulls the `Chick` fields inherited from `Fowl` twice. This has probably something to do with table aliases.

Unlike most other `select_related` issues that simply fail to provide an optimization, this issue returns a faulty output which is pretty serious. Also worth mentioning, the admin calls `select_related` on every field present in list_display which leads to `ChangeList` displaying completely incorrect data .
"	Bug	closed	Database layer (models, ORM)	dev	Normal	fixed			Accepted	0	0	0	0	0	0
