mirror of
https://github.com/django/django.git
synced 2025-08-03 10:34:04 +00:00
Fixed #29076 -- Made Model.refresh_from_db() clear cached relationships even if the related id doesn't change.
This commit is contained in:
parent
46b3e3ffdc
commit
136bf5c214
3 changed files with 15 additions and 12 deletions
|
@ -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')
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue