Fixed #29076 -- Made Model.refresh_from_db() clear cached relationships even if the related id doesn't change.

This commit is contained in:
Jon Dufresne 2018-01-30 07:43:53 -08:00 committed by Tim Graham
parent 46b3e3ffdc
commit 136bf5c214
3 changed files with 15 additions and 12 deletions

View file

@ -722,3 +722,15 @@ class ModelRefreshTests(TestCase):
FeaturedArticle.objects.create(article_id=article.pk)
article.refresh_from_db()
self.assertTrue(hasattr(article, 'featured'))
def test_refresh_clears_one_to_one_field(self):
article = Article.objects.create(
headline='Parrot programs in Python',
pub_date=datetime(2005, 7, 28),
)
featured = FeaturedArticle.objects.create(article_id=article.pk)
self.assertEqual(featured.article.headline, 'Parrot programs in Python')
article.headline = 'Parrot programs in Python 2.0'
article.save()
featured.refresh_from_db()
self.assertEqual(featured.article.headline, 'Parrot programs in Python 2.0')