Fixed #22998 -- Updated the fast_delete logic for GFKs

This commit is contained in:
Gavin Wahl 2014-07-14 10:42:14 -06:00 committed by Anssi Kääriäinen
parent 28efafa24c
commit 6e2b82fdf6
3 changed files with 41 additions and 4 deletions

View file

@ -2,11 +2,14 @@ from django.db.models import Q, Sum
from django.db.utils import IntegrityError
from django.test import TestCase, skipIfDBFeature
from django.forms.models import modelform_factory
from django.db.models.deletion import ProtectedError
from .models import (
Address, Place, Restaurant, Link, CharLink, TextLink,
Person, Contact, Note, Organization, OddRelation1, OddRelation2, Company,
Developer, Team, Guild, Tag, Board, HasLinkThing, A, B, C, D)
Developer, Team, Guild, Tag, Board, HasLinkThing, A, B, C, D,
Related, Content, Node,
)
class GenericRelationTests(TestCase):
@ -247,3 +250,13 @@ class GenericRelationTests(TestCase):
form.save()
links = HasLinkThing._meta.get_field_by_name('links')[0]
self.assertEqual(links.save_form_data_calls, 1)
def test_ticket_22998(self):
related = Related.objects.create()
content = Content.objects.create(related_obj=related)
node = Node.objects.create(content=content)
# deleting the Related cascades to the Content cascades to the Node,
# where the pre_delete signal should fire and prevent deletion.
with self.assertRaises(ProtectedError):
related.delete()