Opened 16 years ago

Closed 16 years ago

Last modified 13 years ago

#10157 closed (fixed)

Assignment to a reverse OneToOne overwrites related object's PK

Reported by: Pavel Anossov Owned by: ianschenck
Component: Database layer (models, ORM) Version: dev
Severity: Keywords: onetoone
Cc: dgouldin@… Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

example models:

class User(models.Model):
    name = models.CharField(max_length=10)
    def __unicode__(self):
        return '<USER: %s>' % self.name
        
class UserProfile(models.Model):
    user = models.OneToOneField(User, related_name='profile', null=True)


When I try to assign a UserProfile instance to a User instance's “profile” attribute, UserProfile's PK AutoField gets overwritten with the User instance:

>>> u = User(name='test')
>>> p = UserProfile()
>>> print p.id, p.user
None None
>>> u.profile = p
>>> print p.id, p.user
<USER test> <USER test>
# Expected: None <USER test>

Attachments (2)

10157.diff (920 bytes ) - added by David Gouldin 16 years ago.
10157_2.diff (1.3 KB ) - added by David Gouldin 16 years ago.

Download all attachments as: .zip

Change History (11)

comment:1 by Jacob, 16 years ago

milestone: 1.1
Triage Stage: UnreviewedAccepted

comment:2 by ianschenck, 16 years ago

Owner: changed from nobody to ianschenck

by David Gouldin, 16 years ago

Attachment: 10157.diff added

comment:3 by David Gouldin, 16 years ago

Cc: dgouldin@… added
Has patch: set

comment:4 by Jacob, 16 years ago

Triage Stage: AcceptedReady for checkin

comment:5 by Jacob, 16 years ago

Triage Stage: Ready for checkinAccepted

Oh, wait, needs a test.

by David Gouldin, 16 years ago

Attachment: 10157_2.diff added

comment:6 by Jacob, 16 years ago

Triage Stage: AcceptedReady for checkin

comment:7 by Jacob, 16 years ago

Resolution: fixed
Status: newclosed

(In [10224]) Fixed #10157: correctly set the related objects pk when assigning a reverse OneToOne. Thanks, dgouldin.

comment:8 by Jacob, 16 years ago

(In [10291]) [1.0.X] Fixed #10157: correctly set the related objects pk when assigning a reverse OneToOne. Thanks, dgouldin.

Backport of r10224 from trunk.

comment:9 by Jacob, 13 years ago

milestone: 1.1

Milestone 1.1 deleted

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