From 123b1d3fcf79f091573c40be6da7113a6ef35b62 Mon Sep 17 00:00:00 2001 From: Bhuvnesh Date: Mon, 7 Nov 2022 12:36:30 +0530 Subject: Fixed #34137 -- Made Model.refresh_from_db() clear cached generic relations. Thanks Simon Charette for the implementation idea. --- tests/contenttypes_tests/test_fields.py | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'tests') diff --git a/tests/contenttypes_tests/test_fields.py b/tests/contenttypes_tests/test_fields.py index 170b38d018..418669140b 100644 --- a/tests/contenttypes_tests/test_fields.py +++ b/tests/contenttypes_tests/test_fields.py @@ -43,6 +43,14 @@ class GenericForeignKeyTests(TestCase): self.assertIsNone(post.parent) self.assertIsNone(post.parent) + def test_clear_cached_generic_relation(self): + question = Question.objects.create(text="What is your name?") + answer = Answer.objects.create(text="Answer", question=question) + old_entity = answer.question + answer.refresh_from_db() + new_entity = answer.question + self.assertIsNot(old_entity, new_entity) + class GenericRelationTests(TestCase): def test_value_to_string(self): -- cgit v1.3