#24578: prepare_database_save breaks some OneToOneField's in 1.8
-------------------------------+--------------------
     Reporter:  dxiao2003      |      Owner:  nobody
         Type:  Uncategorized  |     Status:  new
    Component:  Uncategorized  |    Version:  1.8
     Severity:  Normal         |   Keywords:
 Triage Stage:  Unreviewed     |  Has patch:  0
Easy pickings:  0              |      UI/UX:  0
-------------------------------+--------------------
 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.

--
Ticket URL: <https://code.djangoproject.com/ticket/24578>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/052.29b7934151d20246fd3c5569adc01ced%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to