Opened 9 years ago

Closed 9 years ago

#14163 closed (wontfix)

Setting pk should set the related fields also in the base chain.

Reported by: Anssi Kääriäinen Owned by: nobody
Component: Database layer (models, ORM) Version: 1.2
Severity: Keywords: Inheritance, parent_link, OneToOneField
Cc: Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


Consider two models:

class A(models.Model):

class B(A):
    a = models.OneToOneField(A, parent_link=True, primary_key=True)

creating an b instance and setting its pk should also set the

>>> b = B(pk=1)
>>> b.a_id

At the moment we will get:

>>> is None

It would be even better if setting would also set b.a_id, but that is harder to do, and maybe it isn't that important.

Attachments (1)

inheritance_pk.diff (2.1 KB) - added by Anssi Kääriäinen 9 years ago.
Made sure to test pk property directly

Download all attachments as: .zip

Change History (3)

Changed 9 years ago by Anssi Kääriäinen

Attachment: inheritance_pk.diff added

Made sure to test pk property directly

comment:1 Changed 9 years ago by Anssi Kääriäinen

Has patch: set

comment:2 Changed 9 years ago by Russell Keith-Magee

Resolution: wontfix
Status: newclosed

This all hinges on a matter of interpretation -- whether you consider the Python object to be a reflection of an actual object, or just a representation of a row in a table.

If the behavior of Django objects was the former, reassigning a primary key would change the primary key of the existing object, in which case, updating primary key values would make sense.

However, the current behavior of Django objects is the latter -- when you reassign the primary key of an object, a new object is created. To my reading, that doesn't automatically imply that any existing objects should follow and point to the new object.

Closing wontfix.

Note: See TracTickets for help on using tickets.
Back to Top