diff options
author | Eugene Hatsko <e.hacko.nicecode@gmail.com> | 2020-01-21 10:12:25 +0300 |
---|---|---|
committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2020-01-22 08:25:23 +0100 |
commit | a56e45a2bfc75116451c4e24fce82aa1827edb11 (patch) | |
tree | 5add1aee6ca1041b7aac2d7aefc4568e7a12f14d /tests | |
parent | d7e4d6463c2fda11214e002ee6b3189f7b882f15 (diff) | |
download | django-a56e45a2bfc75116451c4e24fce82aa1827edb11.tar.gz |
[3.0.x] Fixed #31190 -- Fixed prefetch_related() crash for GenericForeignKey with custom ContentType foreign key.
Regression in dffa3e1992562ba60512d96d1eb5859ffff2ceb5.
Backport of 0b013564ef0609d95b1d263626f2e15bccda1a50 from master
Diffstat (limited to 'tests')
-rw-r--r-- | tests/generic_relations/tests.py | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/tests/generic_relations/tests.py b/tests/generic_relations/tests.py index 7c0db95908..683efaddfb 100644 --- a/tests/generic_relations/tests.py +++ b/tests/generic_relations/tests.py @@ -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): |