1
0
mirror of https://github.com/django/django.git synced 2025-10-31 09:41:08 +00:00

[5.1.x] Fixed #35950 -- Restored refreshing of relations when fields deferred.

Thank you to Simon Charette and Sarah Boyce for the review.

Regression in 73df8b54a2.

Backport of 2f6b096b83 from main.
This commit is contained in:
Adam Johnson
2024-11-30 08:03:55 +00:00
committed by Sarah Boyce
parent ee2698dcca
commit 6e3e7353e0
4 changed files with 31 additions and 9 deletions

View File

@@ -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):