﻿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
18252	Multi-table inheritance + ForeignKey to parent => corrupted save	magon@…	nobody	"I have a models like in this minimal test case:
{{{
class A(models.Model):
    title = models.CharField(max_length=100)

    def __str__(self):
        return ""Title(%s)"" % self.title

class B(models.Model):
    more = models.CharField(max_length=100)

    def __str__(self):
        return ""More(%s)"" % (self.more)

#class C(B, A):
class C(A, B):
    def __str__(self):
        return ""%s %s %s"" % (self.problem, self.title, self.more)
    problem = models.ForeignKey(B, related_name='problem')

}}}

Saving ""C"" is corrupted in this case.[[BR]]
It is best ilustrated here:
{{{
Presave:
    More(more 1) title more 2
Retrieved afted save:
    More(more 2) title more 2
}}}

It should output the same two lines, but the the second is different.[[BR]]
Here are the queries performed:
{{{
{'time': '0.000', 'sql': u'INSERT INTO ""save_b"" (""more"") VALUES (more 1)'}
{'time': '0.000', 'sql': u'INSERT INTO ""save_a"" (""title"") VALUES (title)'}
{'time': '0.000', 'sql': u'SELECT (1) AS ""a"" FROM ""save_b"" WHERE ""save_b"".""id"" = 1  LIMIT 1'}
{'time': '0.000', 'sql': u'UPDATE ""save_b"" SET ""more"" = more 2 WHERE ""save_b"".""id"" = 1 '}
{'time': '0.000', 'sql': u'SELECT (1) AS ""a"" FROM ""save_c"" WHERE ""save_c"".""a_ptr_id"" = 1  LIMIT 1'}
{'time': '0.000', 'sql': u'INSERT INTO ""save_c"" (""b_ptr_id"", ""a_ptr_id"", ""problem_id"") SELECT 1 AS ""b_ptr_id"", 1 AS ""a_ptr_id"", 1 AS ""problem_id""'}
{'time': '0.000', 'sql': u'SELECT ""save_a"".""id"", ""save_a"".""title"", ""save_b"".""id"", ""save_b"".""more"", ""save_c"".""b_ptr_id"", ""save_c"".""a_ptr_id"", ""save_c"".""problem_id"" FROM ""save_c"" INNER JOIN ""save_b"" ON (""save_c"".""b_ptr_id"" = ""save_b"".""id"") INNER JOIN ""save_a"" ON (""save_c"".""a_ptr_id"" = ""save_a"".""id"") WHERE ""save_c"".""b_ptr_id"" = 1 '}
{'time': '0.000', 'sql': u'SELECT ""save_b"".""id"", ""save_b"".""more"" FROM ""save_b"" WHERE ""save_b"".""id"" = 1 '}
}}}
The problem is in the ""UPDATE"" there. It should be an insert. It seems like it have set ""pk"" after the first line, but it should be unset.

Interchanging the commented line with the one below solves the problem. But for another reasons I need them this way, not the other way around."	Bug	closed	Database layer (models, ORM)	1.4	Normal	duplicate			Unreviewed	0	1	0	0	0	0
