#24578 closed Bug (fixed)
prepare_database_save breaks some OneToOneField's in 1.8
Reported by: | dxiao2003 | Owned by: | Tim Graham |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | 1.8 |
Severity: | Release blocker | Keywords: | |
Cc: | Triage Stage: | Accepted | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
With 1.8 the following doesn't work:
# models.py from django.db import models class A(models.Model): pass class Aprime(models.Model): original = models.OneToOneField(A, primary_key=True) class B(models.Model): aprime = models.ForeignKey(Aprime) # tests.py from django.test import TestCase from models import * class TestTestCase(TestCase): def test_ref(self): a_one = A.objects.create() a_two = A.objects.create() self.assertNotEqual(a_one, a_two) aprime = Aprime.objects.create(original=a_one) aprime2 = Aprime.objects.create(original=a_two) b = B.objects.create(aprime=aprime) self.assertEqual(b.aprime, aprime) B.objects.update(aprime=aprime2) b = B.objects.get(pk=b.id) self.assertEqual(b.aprime, aprime2)
This throws a InterfaceError: Error binding parameter 0 - probably unsupported type.
when calling B.objects.update(aprime=aprime2)
.
The bug disappears when overriding prepare_database_save
to just return self.pk
instead of getattr(self, field.rel.field_name)
. (This was the behavior as of 1.7 and the bug does not occur there.)
Not sure why prepare_database_save
was modified but this bug actually affects a project of mine so would suggest rolling back to the 1.7 version.
Change History (6)
comment:1 by , 10 years ago
Component: | Uncategorized → Database layer (models, ORM) |
---|---|
Type: | Uncategorized → Bug |
comment:2 by , 10 years ago
Severity: | Normal → Release blocker |
---|---|
Triage Stage: | Unreviewed → Accepted |
comment:3 by , 10 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
Note:
See TracTickets
for help on using tickets.
Bisected to dec93d89912965f94f9e942f0a89ca586fb91454.