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

Fixed #33191 -- Avoided clearing cached reference when saving child after parent.

Thanks Barry Johnson for the report.
This commit is contained in:
Allen Jonathan David
2022-05-27 17:43:12 +05:30
committed by Mariusz Felisiak
parent f1e0fc645b
commit 1058fc7023
2 changed files with 13 additions and 3 deletions

View File

@@ -654,6 +654,16 @@ class ManyToOneTests(TestCase):
self.assertIsNot(c.parent, p)
self.assertEqual(c.parent, p)
def test_save_parent_after_assign(self):
category = Category(name="cats")
record = Record(category=category)
category.save()
record.save()
category.name = "dogs"
with self.assertNumQueries(0):
self.assertEqual(category.id, record.category_id)
self.assertEqual(category.name, record.category.name)
def test_save_nullable_fk_after_parent(self):
parent = Parent()
child = ChildNullableParent(parent=parent)