#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)
Change History (11)
comment:1 by , 16 years ago
milestone: | → 1.1 |
---|---|
Triage Stage: | Unreviewed → Accepted |
comment:2 by , 16 years ago
Owner: | changed from | to
---|
by , 16 years ago
Attachment: | 10157.diff added |
---|
comment:3 by , 16 years ago
Cc: | added |
---|---|
Has patch: | set |
comment:4 by , 16 years ago
Triage Stage: | Accepted → Ready for checkin |
---|
comment:5 by , 16 years ago
Triage Stage: | Ready for checkin → Accepted |
---|
by , 16 years ago
Attachment: | 10157_2.diff added |
---|
comment:6 by , 16 years ago
Triage Stage: | Accepted → Ready for checkin |
---|
comment:7 by , 16 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
comment:8 by , 16 years ago
Note:
See TracTickets
for help on using tickets.
Oh, wait, needs a test.