summaryrefslogtreecommitdiff
path: root/tests/basic/tests.py
diff options
context:
space:
mode:
authorTim Graham <timograham@gmail.com>2016-06-21 13:46:22 -0400
committerTim Graham <timograham@gmail.com>2016-06-21 15:25:16 -0400
commit45a650777e4674bc540c3bf4b3108409f0e1f98a (patch)
tree57fd62fcbc5788fe87b22d9ecb77aa9abdeb8011 /tests/basic/tests.py
parentc464cf88ff5eeabea0109daee35dba8a32f8644d (diff)
[1.10.x] Fixed #26787 -- Documented deleting and reloading of model instance fields.
Thanks Julien Hartmann for the report. Backport of 20d1cb33c2ec1242e16c49deb88e8c70517b2d1a from master
Diffstat (limited to 'tests/basic/tests.py')
-rw-r--r--tests/basic/tests.py13
1 files changed, 13 insertions, 0 deletions
diff --git a/tests/basic/tests.py b/tests/basic/tests.py
index 56b778c419..16c9dd9dae 100644
--- a/tests/basic/tests.py
+++ b/tests/basic/tests.py
@@ -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):