mirror of
https://github.com/django/django.git
synced 2025-10-24 06:06:09 +00:00
Refs #27852 -- Fixed object deletion to show all protected related objects rather than just the first one.
Thanks Anton Samarchyan for the initial patch.
This commit is contained in:
committed by
Mariusz Felisiak
parent
e348ab0d43
commit
ab3cbd8b9a
@@ -1,12 +1,14 @@
|
||||
from math import ceil
|
||||
|
||||
from django.db import IntegrityError, connection, models
|
||||
from django.db.models.deletion import Collector, RestrictedError
|
||||
from django.db.models.deletion import (
|
||||
Collector, ProtectedError, RestrictedError,
|
||||
)
|
||||
from django.db.models.sql.constants import GET_ITERATOR_CHUNK_SIZE
|
||||
from django.test import TestCase, skipIfDBFeature, skipUnlessDBFeature
|
||||
|
||||
from .models import (
|
||||
B1, B2, MR, A, Avatar, Base, Child, DeleteBottom, DeleteTop, GenericB1,
|
||||
B1, B2, MR, A, Avatar, B, Base, Child, DeleteBottom, DeleteTop, GenericB1,
|
||||
GenericB2, GenericDeleteBottom, HiddenUser, HiddenUserProfile, M, M2MFrom,
|
||||
M2MTo, MRNull, Origin, P, Parent, R, RChild, RChildChild, Referrer, S, T,
|
||||
User, create_a, get_default_r,
|
||||
@@ -72,11 +74,22 @@ class OnDeleteTests(TestCase):
|
||||
a = create_a('protect')
|
||||
msg = (
|
||||
"Cannot delete some instances of model 'R' because they are "
|
||||
"referenced through a protected foreign key: 'A.protect'"
|
||||
"referenced through protected foreign keys: 'A.protect'."
|
||||
)
|
||||
with self.assertRaisesMessage(IntegrityError, msg):
|
||||
a.protect.delete()
|
||||
|
||||
def test_protect_multiple(self):
|
||||
a = create_a('protect')
|
||||
B.objects.create(protect=a.protect)
|
||||
msg = (
|
||||
"Cannot delete some instances of model 'R' because they are "
|
||||
"referenced through protected foreign keys: 'A.protect', "
|
||||
"'B.protect'."
|
||||
)
|
||||
with self.assertRaisesMessage(ProtectedError, msg):
|
||||
a.protect.delete()
|
||||
|
||||
def test_do_nothing(self):
|
||||
# Testing DO_NOTHING is a bit harder: It would raise IntegrityError for a normal model,
|
||||
# so we connect to pre_delete and set the fk to a known value.
|
||||
|
||||
Reference in New Issue
Block a user