Skip to content

Commit

Permalink
Refs #35044 -- Added Model.refresh_from_db(fields=...) test for clear…
Browse files Browse the repository at this point in the history
…ing reverse relations.
  • Loading branch information
g-nie authored and felixxm committed Mar 8, 2024
1 parent 2d3531a commit 0c690c6
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions tests/basic/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -966,6 +966,13 @@ def test_refresh_clears_reverse_related(self):
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",
Expand Down

0 comments on commit 0c690c6

Please sign in to comment.