Refs #35044 -- Added Model.refresh_from_db(fields=...) test for clearing reverse relations.

This commit is contained in:
Giannis Terzopoulos 2024-03-08 10:27:19 +01:00 committed by Mariusz Felisiak
parent 2d3531af23
commit 0c690c6001
1 changed files with 7 additions and 0 deletions

View File

@ -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",