Ticket #32107: objects.patch

File objects.patch, 3.4 KB (added by Kwist, 4 years ago)

Patch

  • django/db/models/deletion.py

    diff --git a/django/db/models/deletion.py b/django/db/models/deletion.py
    index 3bdd89cbd9..4d3823b3dd 100644
    a b class Collector:  
    305305                    model.__name__,
    306306                    ', '.join(protected_objects),
    307307                ),
    308                 chain.from_iterable(protected_objects.values()),
     308                list(chain.from_iterable(protected_objects.values())),
    309309            )
    310310        for related_model, related_fields in model_fast_deletes.items():
    311311            batches = self.get_del_batches(new_objs, related_fields)
    class Collector:  
    340340                            model.__name__,
    341341                            ', '.join(restricted_objects),
    342342                        ),
    343                         chain.from_iterable(restricted_objects.values()),
     343                        list(chain.from_iterable(restricted_objects.values())),
    344344                    )
    345345
    346346    def related_objects(self, related_model, related_fields, objs):
  • tests/delete/tests.py

    diff --git a/tests/delete/tests.py b/tests/delete/tests.py
    index 485ae1aaf5..7bcedcf91c 100644
    a b class OnDeleteTests(TestCase):  
    7676            "referenced through protected foreign keys: 'A.protect'."
    7777        )
    7878        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
    8084
    8185    def test_protect_multiple(self):
    8286        a = create_a('protect')
    83         B.objects.create(protect=a.protect)
     87        b = B.objects.create(protect=a.protect)
    8488        msg = (
    8589            "Cannot delete some instances of model 'R' because they are "
    8690            "referenced through protected foreign keys: 'A.protect', "
    8791            "'B.protect'."
    8892        )
    8993        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
    9199
    92100    def test_protect_path(self):
    93101        a = create_a('protect')
    class OnDeleteTests(TestCase):  
    177185            "referenced through restricted foreign keys: 'A.restrict'."
    178186        )
    179187        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
    181193
    182194    def test_restrict_multiple(self):
    183195        a = create_a('restrict')
    184         B3.objects.create(restrict=a.restrict)
     196        b = B3.objects.create(restrict=a.restrict)
    185197        msg = (
    186198            "Cannot delete some instances of model 'R' because they are "
    187199            "referenced through restricted foreign keys: 'A.restrict', "
    188200            "'B3.restrict'."
    189201        )
    190202        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
    192208
    193209    def test_restrict_path_cascade_indirect(self):
    194210        a = create_a('restrict')
Back to Top