From 0c690c60012e6a2f0cde0fc564c55054c465d02f Mon Sep 17 00:00:00 2001 From: Giannis Terzopoulos Date: Fri, 8 Mar 2024 10:27:19 +0100 Subject: [PATCH] Refs #35044 -- Added Model.refresh_from_db(fields=...) test for clearing reverse relations. --- tests/basic/tests.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/basic/tests.py b/tests/basic/tests.py index 8a304e9ace0..bda59d82fa8 100644 --- a/tests/basic/tests.py +++ b/tests/basic/tests.py @@ -966,6 +966,13 @@ class ModelRefreshTests(TestCase): article.refresh_from_db() self.assertTrue(hasattr(article, "featured")) + def test_refresh_clears_reverse_related_explicit_fields(self): + article = Article.objects.create(headline="Test", pub_date=datetime(2024, 2, 4)) + self.assertFalse(hasattr(article, "featured")) + FeaturedArticle.objects.create(article_id=article.pk) + article.refresh_from_db(fields=["featured"]) + self.assertTrue(hasattr(article, "featured")) + def test_refresh_clears_one_to_one_field(self): article = Article.objects.create( headline="Parrot programs in Python",