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):
|
215 | 215 | raise ProtectedError("Not allowed to delete.", [instance]) |
216 | 216 | |
217 | 217 | models.signals.pre_delete.connect(prevent_deletes, sender=Node) |
| 218 | |
| 219 | |
| 220 | class OtherSuper(models.Model): |
| 221 | pass |
| 222 | |
| 223 | |
| 224 | class OtherSub(OtherSuper): |
| 225 | pass |
| 226 | |
| 227 | |
| 228 | class 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') |
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):
|
276 | 276 | def test_ticket_22982(self): |
277 | 277 | place = Place.objects.create(name='My Place') |
278 | 278 | 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 | ) |