Opened 14 years ago

Closed 13 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

Description

Consider two models:

class A(models.Model):
    pass

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 a.id:

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

At the moment we will get:

>>> b.id is None
True

It would be even better if setting b.id 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 14 years ago.
Made sure to test pk property directly

Download all attachments as: .zip

Change History (3)

by Anssi Kääriäinen, 14 years ago

Attachment: inheritance_pk.diff added

Made sure to test pk property directly

comment:1 by Anssi Kääriäinen, 14 years ago

Has patch: set

comment:2 by Russell Keith-Magee, 13 years ago

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