﻿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
14096	Insert code generated by models using multiple inheritance is incorrect and fails in postgresql	Arthur Pemberton	nobody	"When a model with multiple concrete parents is saved (inserted) the parents are saved first. Currently, the first parent is saved and its primary key is also set as the primary key of the yet unsaved top model. Any parent following uses the new primary key of 'self' and explicitly inserts the PK into the parent models table

There is no reason to explicitly set the PK of any of the parent classes, the code already handles retrieval of the DB assigned PK.

While other DBs let this pass, PostgreSQL does not. The problem comes not on the offending .save() but subsequent inserts to the table, this time '''without''' an explicit PK. The DB's internal counter has not advanced, so the next chosen PK already exists and yields a database error due to duplicate of a key field.

There is no apparent need to explicitly set any of the PK on insert. I believe that changing the following code block within source:django/trunk/django/db/models/base.py#13538 , line 533 , Model.save_base(...) can solve the problem:

from
{{{
#!python
                if update_pk:
                    setattr(self, meta.pk.attname, result)
}}}

to
{{{
#!python
                if update_pk and cls == self.__class__:
                    setattr(self, meta.pk.attname, result)
}}}

I have attached a sample site ('minherit') with app ('data') and a test case in a ZIP file."	Bug	closed	Database layer (models, ORM)	1.2	Normal	invalid	orm		Accepted	1	0	1	1	0	0
