summaryrefslogtreecommitdiff
path: root/tests/basic
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 14:39:17 -0400
commit20d1cb33c2ec1242e16c49deb88e8c70517b2d1a (patch)
tree06b35c67c0e5cc5f39c4e9863b6cdb1b227a3f8b /tests/basic
parent9c2d5a8d333277cc1b482a9d05f174cf4d09f24c (diff)
downloaddjango-20d1cb33c2ec1242e16c49deb88e8c70517b2d1a.tar.gz
Fixed #26787 -- Documented deleting and reloading of model instance fields.
Thanks Julien Hartmann for the report.
Diffstat (limited to 'tests/basic')
-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):