diff --git a/django/db/models/deletion.py b/django/db/models/deletion.py
index 3bdd89cbd9..4d3823b3dd 100644
a
|
b
|
class Collector:
|
305 | 305 | model.__name__, |
306 | 306 | ', '.join(protected_objects), |
307 | 307 | ), |
308 | | chain.from_iterable(protected_objects.values()), |
| 308 | list(chain.from_iterable(protected_objects.values())), |
309 | 309 | ) |
310 | 310 | for related_model, related_fields in model_fast_deletes.items(): |
311 | 311 | batches = self.get_del_batches(new_objs, related_fields) |
… |
… |
class Collector:
|
340 | 340 | model.__name__, |
341 | 341 | ', '.join(restricted_objects), |
342 | 342 | ), |
343 | | chain.from_iterable(restricted_objects.values()), |
| 343 | list(chain.from_iterable(restricted_objects.values())), |
344 | 344 | ) |
345 | 345 | |
346 | 346 | def related_objects(self, related_model, related_fields, objs): |
diff --git a/tests/delete/tests.py b/tests/delete/tests.py
index 485ae1aaf5..7bcedcf91c 100644
a
|
b
|
class OnDeleteTests(TestCase):
|
76 | 76 | "referenced through protected foreign keys: 'A.protect'." |
77 | 77 | ) |
78 | 78 | with self.assertRaisesMessage(ProtectedError, msg): |
79 | | a.protect.delete() |
| 79 | try: |
| 80 | a.protect.delete() |
| 81 | except ProtectedError as exc: |
| 82 | self.assertEqual(set(exc.protected_objects), {a}) |
| 83 | raise |
80 | 84 | |
81 | 85 | def test_protect_multiple(self): |
82 | 86 | a = create_a('protect') |
83 | | B.objects.create(protect=a.protect) |
| 87 | b = B.objects.create(protect=a.protect) |
84 | 88 | msg = ( |
85 | 89 | "Cannot delete some instances of model 'R' because they are " |
86 | 90 | "referenced through protected foreign keys: 'A.protect', " |
87 | 91 | "'B.protect'." |
88 | 92 | ) |
89 | 93 | with self.assertRaisesMessage(ProtectedError, msg): |
90 | | a.protect.delete() |
| 94 | try: |
| 95 | a.protect.delete() |
| 96 | except ProtectedError as exc: |
| 97 | self.assertEqual(set(exc.protected_objects), {a, b}) |
| 98 | raise |
91 | 99 | |
92 | 100 | def test_protect_path(self): |
93 | 101 | a = create_a('protect') |
… |
… |
class OnDeleteTests(TestCase):
|
177 | 185 | "referenced through restricted foreign keys: 'A.restrict'." |
178 | 186 | ) |
179 | 187 | with self.assertRaisesMessage(RestrictedError, msg): |
180 | | a.restrict.delete() |
| 188 | try: |
| 189 | a.restrict.delete() |
| 190 | except RestrictedError as exc: |
| 191 | self.assertEqual(set(exc.restricted_objects), {a}) |
| 192 | raise |
181 | 193 | |
182 | 194 | def test_restrict_multiple(self): |
183 | 195 | a = create_a('restrict') |
184 | | B3.objects.create(restrict=a.restrict) |
| 196 | b = B3.objects.create(restrict=a.restrict) |
185 | 197 | msg = ( |
186 | 198 | "Cannot delete some instances of model 'R' because they are " |
187 | 199 | "referenced through restricted foreign keys: 'A.restrict', " |
188 | 200 | "'B3.restrict'." |
189 | 201 | ) |
190 | 202 | with self.assertRaisesMessage(RestrictedError, msg): |
191 | | a.restrict.delete() |
| 203 | try: |
| 204 | a.restrict.delete() |
| 205 | except RestrictedError as exc: |
| 206 | self.assertEqual(set(exc.restricted_objects), {a, b}) |
| 207 | raise |
192 | 208 | |
193 | 209 | def test_restrict_path_cascade_indirect(self): |
194 | 210 | a = create_a('restrict') |