Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #9023 -- Corrected a problem where cached attribute values woul…

…d cause a delete to cascade to a related object even when the relationship had been set to None. Thanks to TheShark for the report and test case, and to juriejan and Jacob for their work on the patch.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@11009 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 191203b48d2cd593b9adcf99ba2c91db64c40cd1 1 parent b38cf5d
Russell Keith-Magee authored June 15, 2009
29  django/db/models/fields/related.py
@@ -112,9 +112,9 @@ def set_attributes_from_rel(self):
@@ -184,7 +184,6 @@ def __init__(self, related):
@@ -232,6 +231,7 @@ def __init__(self, field_with_rel):
@@ -272,6 +272,29 @@ def __set__(self, instance, value):
22  tests/regressiontests/one_to_one_regress/tests.py
... ...
@@ -0,0 +1,22 @@
  1
+from django.test import TestCase
  2
+from regressiontests.one_to_one_regress.models import Place, UndergroundBar
  3
+
  4
+class OneToOneDeletionTests(TestCase):
  5
+    def test_reverse_relationship_cache_cascade(self):
  6
+        """
  7
+        Regression test for #9023: accessing the reverse relationship shouldn't
  8
+        result in a cascading delete().
  9
+        """
  10
+        place = Place.objects.create(name="Dempsey's", address="623 Vermont St")
  11
+        bar = UndergroundBar.objects.create(place=place, serves_cocktails=False)
  12
+
  13
+        # The bug in #9023: if you access the one-to-one relation *before*
  14
+        # setting to None and deleting, the cascade happens anyway.
  15
+        place.undergroundbar
  16
+        bar.place.name='foo'
  17
+        bar.place = None
  18
+        bar.save()
  19
+        place.delete()
  20
+
  21
+        self.assertEqual(Place.objects.all().count(), 0)
  22
+        self.assertEqual(UndergroundBar.objects.all().count(), 1)

0 notes on commit 191203b

Please sign in to comment.
Something went wrong with that request. Please try again.