mirror of
https://github.com/django/django.git
synced 2025-08-04 19:08:28 +00:00
Fixed #31190 -- Fixed prefetch_related() crash for GenericForeignKey with custom ContentType foreign key.
Regression in dffa3e1992
.
This commit is contained in:
parent
b753e0e750
commit
0b013564ef
3 changed files with 19 additions and 1 deletions
|
@ -564,6 +564,19 @@ class GenericRelationsTests(TestCase):
|
|||
for tag in tags:
|
||||
self.assertSequenceEqual(tag.content_object.tags.all(), [tag])
|
||||
|
||||
def test_prefetch_related_custom_object_id(self):
|
||||
tiger = Animal.objects.create(common_name='tiger')
|
||||
cheetah = Animal.objects.create(common_name='cheetah')
|
||||
Comparison.objects.create(
|
||||
first_obj=cheetah, other_obj=tiger, comparative='faster',
|
||||
)
|
||||
Comparison.objects.create(
|
||||
first_obj=tiger, other_obj=cheetah, comparative='cooler',
|
||||
)
|
||||
qs = Comparison.objects.prefetch_related('first_obj__comparisons')
|
||||
for comparison in qs:
|
||||
self.assertSequenceEqual(comparison.first_obj.comparisons.all(), [comparison])
|
||||
|
||||
|
||||
class ProxyRelatedModelTest(TestCase):
|
||||
def test_default_behavior(self):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue