#14096: Insert code generated by models using multiple inheritance is incorrect
and
fails in postgresql
------------------------------------------+---------------------------------
Reporter: pembo13 | Owner: nobody
Status: new | Milestone:
Component: Database layer (models, ORM) | Version: 1.2
Keywords: orm | Stage: Unreviewed
Has_patch: 0 |
------------------------------------------+---------------------------------
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.
--
Ticket URL: <http://code.djangoproject.com/ticket/14096>
Django <http://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/django-updates?hl=en.