1
0
mirror of https://github.com/django/django.git synced 2025-10-24 14:16:09 +00:00

Fixed #26787 -- Documented deleting and reloading of model instance fields.

Thanks Julien Hartmann for the report.
This commit is contained in:
Tim Graham
2016-06-21 13:46:22 -04:00
parent 9c2d5a8d33
commit 20d1cb33c2
3 changed files with 28 additions and 0 deletions

View File

@@ -421,6 +421,19 @@ class ModelTest(TestCase):
# hash)
hash(Article())
def test_delete_and_access_field(self):
# Accessing a field after it's deleted from a model reloads its value.
pub_date = datetime.now()
article = Article.objects.create(headline='foo', pub_date=pub_date)
new_pub_date = article.pub_date + timedelta(days=10)
article.headline = 'bar'
article.pub_date = new_pub_date
del article.headline
with self.assertNumQueries(1):
self.assertEqual(article.headline, 'foo')
# Fields that weren't deleted aren't reloaded.
self.assertEqual(article.pub_date, new_pub_date)
class ModelLookupTest(TestCase):
def setUp(self):