summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorRussell Keith-Magee <russell@keith-magee.com>2009-06-15 15:06:35 +0000
committerRussell Keith-Magee <russell@keith-magee.com>2009-06-15 15:06:35 +0000
commitd0a3b92e4bf21820c5c91922e32d68449f8ea4d4 (patch)
treebdabfcecb2ef117eca4efc0cfe7f692eae62b4ce /tests
parent8656fffbe0d30c35a7415f8b5928d06ff93e8cc3 (diff)
[1.0.X] Fixed #9023 -- Corrected a problem where cached attribute values would 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.
Merge of r11009 from trunk. git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.0.X@11010 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'tests')
-rw-r--r--tests/regressiontests/one_to_one_regress/tests.py22
1 files changed, 22 insertions, 0 deletions
diff --git a/tests/regressiontests/one_to_one_regress/tests.py b/tests/regressiontests/one_to_one_regress/tests.py
new file mode 100644
index 0000000000..a0a0c0584f
--- /dev/null
+++ b/tests/regressiontests/one_to_one_regress/tests.py
@@ -0,0 +1,22 @@
+from django.test import TestCase
+from regressiontests.one_to_one_regress.models import Place, UndergroundBar
+
+class OneToOneDeletionTests(TestCase):
+ def test_reverse_relationship_cache_cascade(self):
+ """
+ Regression test for #9023: accessing the reverse relationship shouldn't
+ result in a cascading delete().
+ """
+ place = Place.objects.create(name="Dempsey's", address="623 Vermont St")
+ bar = UndergroundBar.objects.create(place=place, serves_cocktails=False)
+
+ # The bug in #9023: if you access the one-to-one relation *before*
+ # setting to None and deleting, the cascade happens anyway.
+ place.undergroundbar
+ bar.place.name='foo'
+ bar.place = None
+ bar.save()
+ place.delete()
+
+ self.assertEqual(Place.objects.all().count(), 0)
+ self.assertEqual(UndergroundBar.objects.all().count(), 1)