diff options
| author | Adam Johnson <me@adamj.eu> | 2024-11-30 08:03:55 +0000 |
|---|---|---|
| committer | Sarah Boyce <42296566+sarahboyce@users.noreply.github.com> | 2024-12-02 16:01:37 +0100 |
| commit | 2f6b096b83c55317c7ceef2d8d5dc3bee33293dc (patch) | |
| tree | 7d17909df90c690f26dcda0eaa6b7fb0b54fd35b /tests | |
| parent | 32b9e00b0c74b3af77c25215e2e2d1254b995355 (diff) | |
Fixed #35950 -- Restored refreshing of relations when fields deferred.
Thank you to Simon Charette and Sarah Boyce for the review.
Regression in 73df8b54a2fab53bec4c7573cda5ad8c869c2fd8.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/contenttypes_tests/test_fields.py | 9 | ||||
| -rw-r--r-- | tests/defer/tests.py | 8 |
2 files changed, 17 insertions, 0 deletions
diff --git a/tests/contenttypes_tests/test_fields.py b/tests/contenttypes_tests/test_fields.py index ab16324fb6..fc49d59b27 100644 --- a/tests/contenttypes_tests/test_fields.py +++ b/tests/contenttypes_tests/test_fields.py @@ -57,6 +57,15 @@ class GenericForeignKeyTests(TestCase): self.assertIsNot(answer.question, old_question_obj) self.assertEqual(answer.question, old_question_obj) + def test_clear_cached_generic_relation_when_deferred(self): + question = Question.objects.create(text="question") + Answer.objects.create(text="answer", question=question) + answer = Answer.objects.defer("text").get() + old_question_obj = answer.question + # The reverse relation is refreshed even when the text field is deferred. + answer.refresh_from_db() + self.assertIsNot(answer.question, old_question_obj) + class GenericRelationTests(TestCase): def test_value_to_string(self): diff --git a/tests/defer/tests.py b/tests/defer/tests.py index 3945b667ba..989b5c63d7 100644 --- a/tests/defer/tests.py +++ b/tests/defer/tests.py @@ -290,6 +290,14 @@ class TestDefer2(AssertionMixin, TestCase): self.assertEqual(rf2.name, "new foo") self.assertEqual(rf2.value, "new bar") + def test_refresh_when_one_field_deferred(self): + s = Secondary.objects.create() + PrimaryOneToOne.objects.create(name="foo", value="bar", related=s) + s = Secondary.objects.defer("first").get() + p_before = s.primary_o2o + s.refresh_from_db() + self.assertIsNot(s.primary_o2o, p_before) + class InvalidDeferTests(SimpleTestCase): def test_invalid_defer(self): |
