diff options
| author | Martin Svoboda <martin.svoboda@gmail.com> | 2021-08-11 16:42:43 +0200 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2021-10-14 12:37:03 +0200 |
| commit | cc4cb95beff0b75ec169add7e94cc481624a41e6 (patch) | |
| tree | 9abb66f50321373edf513ccae36698577d56fe65 /tests/contenttypes_tests | |
| parent | cdad96e6330cd31185f7496aaf8eb316f2773d6d (diff) | |
Fixed #33008 -- Fixed prefetch_related() for deleted GenericForeignKeys.
Thanks Simon Charette for the implementation idea.
Diffstat (limited to 'tests/contenttypes_tests')
| -rw-r--r-- | tests/contenttypes_tests/test_fields.py | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/tests/contenttypes_tests/test_fields.py b/tests/contenttypes_tests/test_fields.py index ce5e244df5..5638846cc5 100644 --- a/tests/contenttypes_tests/test_fields.py +++ b/tests/contenttypes_tests/test_fields.py @@ -2,14 +2,14 @@ import json from django.contrib.contenttypes.fields import GenericForeignKey from django.db import models -from django.test import SimpleTestCase, TestCase +from django.test import TestCase from django.test.utils import isolate_apps -from .models import Answer, Question +from .models import Answer, Post, Question @isolate_apps('contenttypes_tests') -class GenericForeignKeyTests(SimpleTestCase): +class GenericForeignKeyTests(TestCase): def test_str(self): class Model(models.Model): @@ -24,6 +24,19 @@ class GenericForeignKeyTests(SimpleTestCase): with self.assertRaisesMessage(ValueError, "Custom queryset can't be used for this lookup."): Answer.question.get_prefetch_queryset(Answer.objects.all(), Answer.objects.all()) + def test_get_object_cache_respects_deleted_objects(self): + question = Question.objects.create(text='Who?') + post = Post.objects.create(title='Answer', parent=question) + + question_pk = question.pk + Question.objects.all().delete() + + post = Post.objects.get(pk=post.pk) + with self.assertNumQueries(1): + self.assertEqual(post.object_id, question_pk) + self.assertIsNone(post.parent) + self.assertIsNone(post.parent) + class GenericRelationTests(TestCase): |
