1
0
mirror of https://github.com/django/django.git synced 2025-10-31 09:41:08 +00:00

Fixed #34816 -- Fixed GenericForeignKey crash when checking cache for primary keys with different types.

This commit is contained in:
Oguzhan Akan
2023-09-08 09:47:11 +03:00
committed by GitHub
parent 1ab2cf7994
commit e41f9f9450
3 changed files with 15 additions and 2 deletions

View File

@@ -1,3 +1,4 @@
from django.contrib.contenttypes.models import ContentType
from django.db.models import ProtectedError, Q, Sum
from django.forms.models import modelform_factory
from django.test import TestCase, skipIfDBFeature
@@ -332,3 +333,14 @@ class GenericRelationTests(TestCase):
self.assertSequenceEqual(qs, [link2])
qs = Link.objects.exclude(places__name="Test Place 1")
self.assertSequenceEqual(qs, [link2])
def test_check_cached_value_pk_different_type(self):
"""Primary key is not checked if the content type doesn't match."""
board = Board.objects.create(name="some test")
oddrel = OddRelation1.objects.create(name="clink")
charlink = CharLink.objects.create(content_object=oddrel)
charlink = CharLink.objects.get(pk=charlink.pk)
self.assertEqual(charlink.content_object, oddrel)
charlink.object_id = board.pk
charlink.content_type_id = ContentType.objects.get_for_model(Board).id
self.assertEqual(charlink.content_object, board)