mirror of
https://github.com/django/django.git
synced 2025-11-02 21:03:53 +00:00
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.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@11009 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
b38cf5db5c
commit
191203b48d
2 changed files with 48 additions and 3 deletions
22
tests/regressiontests/one_to_one_regress/tests.py
Normal file
22
tests/regressiontests/one_to_one_regress/tests.py
Normal file
|
|
@ -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)
|
||||
Loading…
Add table
Add a link
Reference in a new issue