Commit b773ef8f authored by Anssi Kääriäinen's avatar Anssi Kääriäinen Committed by Andrew Godwin
Browse files

Fixed #14043 -- Made sure nullable o2o delete works as expected

There was an old complaint about nullable one-to-one field cascading
even when the o2o field was saved to None value before the deletion.
Added an test to verify this doesn't happen.

Also some PEP 8 cleanup.
parent 63378163
Loading
Loading
Loading
Loading
+21 −13
Original line number Diff line number Diff line
@@ -114,7 +114,7 @@ class OneToOneRegressionTests(TestCase):
        misbehaving. We test both (primary_key=True & False) cases here to
        prevent any reappearance of the problem.
        """
        t = Target.objects.create()
        Target.objects.create()

        self.assertQuerysetEqual(
            Target.objects.filter(pointer=None),
@@ -235,3 +235,11 @@ class OneToOneRegressionTests(TestCase):
        b = UndergroundBar.objects.create()
        with self.assertNumQueries(0), self.assertRaises(ValueError):
            p.undergroundbar = b

    def test_nullable_o2o_delete(self):
        u = UndergroundBar.objects.create(place=self.p1)
        u.place_id = None
        u.save()
        self.p1.delete()
        self.assertTrue(UndergroundBar.objects.filter(pk=u.pk).exists())
        self.assertIsNone(UndergroundBar.objects.get(pk=u.pk).place)