﻿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
15250	Cannot fill parent model instance in cache	Vlastimil Zíma	Paulo	"Continue of #14371
I tried again in django trunk (tested also in 1.2.4)

I have following models (in SQLite3)
{{{
#!python
class Parent(models.Model):
    parent_int = models.IntegerField()

class Child(Parent):
    child_int = models.IntegerField()
}}}

{{{
#!python
In [1]: from django.db import connection

In [2]: from testmodule.models import Parent, Child

In [3]: Child.objects.create(parent_int = 1, child_int = 2)
Out[3]: <Child: Child object>

In [4]: Child.objects.get(parent_int = 1, child_int = 2).parent_ptr
Out[4]: <Parent: Parent object>

In [5]: connection.queries
Out[5]: 
[{'sql': u'INSERT INTO ""testmodule_parent"" (""parent_int"") VALUES (1)',
  'time': '0.001'},
 {'sql': u'INSERT INTO ""testmodule_child"" (""parent_ptr_id"", ""child_int"") VALUES (2, 2)',
  'time': '0.000'},
 {'sql': u'SELECT ""testmodule_parent"".""id"", ""testmodule_parent"".""parent_int"", ""testmodule_child"".""parent_ptr_id"", ""testmodule_child"".""child_int"" FROM ""testmodule_child"" INNER JOIN ""testmodule_parent"" ON (""testmodule_child"".""parent_ptr_id"" = ""testmodule_parent"".""id"") WHERE (""testmodule_parent"".""parent_int"" = 1  AND ""testmodule_child"".""child_int"" = 2 )',
  'time': '0.000'},
 {'sql': u'SELECT ""testmodule_parent"".""id"", ""testmodule_parent"".""parent_int"" FROM ""testmodule_parent"" WHERE ""testmodule_parent"".""id"" = 2 ',
  'time': '0.000'}]

In [6]: Child.objects.select_related('parent').get(parent_int = 1, child_int = 2).parent_ptr
Out[6]: <Parent: Parent object>

In [7]: connection.queries
Out[7]: 
[{'sql': u'INSERT INTO ""testmodule_parent"" (""parent_int"") VALUES (1)',
  'time': '0.001'},
 {'sql': u'INSERT INTO ""testmodule_child"" (""parent_ptr_id"", ""child_int"") VALUES (2, 2)',
  'time': '0.000'},
 {'sql': u'SELECT ""testmodule_parent"".""id"", ""testmodule_parent"".""parent_int"", ""testmodule_child"".""parent_ptr_id"", ""testmodule_child"".""child_int"" FROM ""testmodule_child"" INNER JOIN ""testmodule_parent"" ON (""testmodule_child"".""parent_ptr_id"" = ""testmodule_parent"".""id"") WHERE (""testmodule_parent"".""parent_int"" = 1  AND ""testmodule_child"".""child_int"" = 2 )',
  'time': '0.000'},
 {'sql': u'SELECT ""testmodule_parent"".""id"", ""testmodule_parent"".""parent_int"" FROM ""testmodule_parent"" WHERE ""testmodule_parent"".""id"" = 2 ',
  'time': '0.000'},
 {'sql': u'SELECT ""testmodule_parent"".""id"", ""testmodule_parent"".""parent_int"", ""testmodule_child"".""parent_ptr_id"", ""testmodule_child"".""child_int"" FROM ""testmodule_child"" INNER JOIN ""testmodule_parent"" ON (""testmodule_child"".""parent_ptr_id"" = ""testmodule_parent"".""id"") WHERE (""testmodule_parent"".""parent_int"" = 1  AND ""testmodule_child"".""child_int"" = 2 )',
  'time': '0.000'},
 {'sql': u'SELECT ""testmodule_parent"".""id"", ""testmodule_parent"".""parent_int"" FROM ""testmodule_parent"" WHERE ""testmodule_parent"".""id"" = 2 ',
  'time': '0.000'}]
}}}

You can see that query is correct for selecting parent, but it's instance is not created in cache as usual and that leads to another select."	Bug	closed	Database layer (models, ORM)	1.2	Normal	fixed			Accepted	1	0	0	1	0	0
