Code

Opened 3 years ago

Closed 3 years ago

#16944 closed Bug (duplicate)

multiple inheritance issue

Reported by: pegler@… Owned by: nobody
Component: Database layer (models, ORM) Version: 1.3
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Django's support for multiple inheritance from several non-abstract models seems to almost be working. When both parent models have the same name for their PK, saving will update a related row instead of insert a new one.

Scenario:

Model: Pet - pk: id
Model: Mammal - pk: id
Model: Cat - inherits from Pet and Mammal, pk on the 2 foreign keys

Cat.save() will first insert a Pet row, since id isn't yet set. It will then set Cat.id to the new id values from Pet. It will then try to save Mammal, but since id has been set from Pet, it will try to update/insert a Mammal row (instead of always inserting).

The code at fault is here: https://code.djangoproject.com/browser/django/tags/releases/1.3.1/django/db/models/base.py#L492

I am not sure of the best solution for this, but perhaps not setting attributes that are also primary keys of other parent models.

Attachments (0)

Change History (1)

comment:1 Changed 3 years ago by anonymous

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Resolution set to duplicate
  • Status changed from new to closed

I think this is #12002.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.