Code

Opened 4 years ago

Closed 4 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:

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

Download all attachments as: .zip

Change History (3)

Changed 4 years ago by akaariai

Made sure to test pk property directly

comment:1 Changed 4 years ago by akaariai

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

comment:2 Changed 4 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.

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.