mirror of
				https://github.com/django/django.git
				synced 2025-10-31 01:25:32 +00:00 
			
		
		
		
	[1.10.x] Fixed #26787 -- Documented deleting and reloading of model instance fields.
Thanks Julien Hartmann for the report.
Backport of 20d1cb33c2 from master
			
			
This commit is contained in:
		| @@ -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): | ||||
|   | ||||
		Reference in New Issue
	
	Block a user