Ticket #28856: 1.10-regression-test.patch

File 1.10-regression-test.patch, 1.7 KB (added by Morgan Wahl, 4 years ago)

patch with regression test

  • tests/generic_relations_regress/models.py

    diff --git a/tests/generic_relations_regress/models.py b/tests/generic_relations_regress/models.py
    index 331c575..59b7215 100644
    a b def prevent_deletes(sender, instance, **kwargs): 
    215215    raise ProtectedError("Not allowed to delete.", [instance])
    216216
    217217models.signals.pre_delete.connect(prevent_deletes, sender=Node)
     218
     219
     220class OtherSuper(models.Model):
     221    pass
     222
     223
     224class OtherSub(OtherSuper):
     225    pass
     226
     227
     228class Ref(models.Model):
     229    obj_type = models.ForeignKey(ContentType, on_delete=models.PROTECT)
     230    obj_id = models.CharField(max_length=255)
     231    obj = GenericForeignKey('obj_type', 'obj_id')
  • tests/generic_relations_regress/tests.py

    diff --git a/tests/generic_relations_regress/tests.py b/tests/generic_relations_regress/tests.py
    index 2c5b13d..ff8d3b0 100644
    a b class GenericRelationTests(TestCase): 
    276276    def test_ticket_22982(self):
    277277        place = Place.objects.create(name='My Place')
    278278        self.assertIn('GenericRelatedObjectManager', str(place.links))
     279
     280    def test_identity(self):
     281        from .models import OtherSub, OtherSuper, Ref
     282
     283        for other_model in (OtherSuper, OtherSub):
     284            with self.subTest(
     285                other_model=other_model.__name__,
     286            ):
     287                other = other_model.objects.create()
     288                ref = Ref.objects.create(obj=other)
     289                # Get a fresh instance to test code that would be fetching an
     290                # existing one.
     291                ref.refresh_from_db()
     292                self.assertEqual(
     293                    id(ref.obj),
     294                    id(ref.obj),
     295                )
Back to Top