Opened 6 years ago

Closed 6 years ago

#14163 closed (wontfix)

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

Reported by: akaariai 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: UI/UX:


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 akaariai 6 years ago.
Made sure to test pk property directly

Download all attachments as: .zip

Change History (3)

Changed 6 years ago by akaariai

Made sure to test pk property directly

comment:1 Changed 6 years ago by akaariai

  • Has patch set
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

comment:2 Changed 6 years ago by russellm

  • Resolution set to wontfix
  • Status changed from new to closed

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