mirror of
				https://github.com/django/django.git
				synced 2025-10-31 09:41:08 +00:00 
			
		
		
		
	[3.0.x] Fixed #30839 -- Fixed Field.__deepcopy__() so forms don't share error messages.
Backport of a28d1b38e5 from master
			
			
This commit is contained in:
		
				
					committed by
					
						 Mariusz Felisiak
						Mariusz Felisiak
					
				
			
			
				
	
			
			
			
						parent
						
							282138a7bb
						
					
				
				
					commit
					7c70aa8f63
				
			| @@ -201,6 +201,7 @@ class Field: | ||||
|         result = copy.copy(self) | ||||
|         memo[id(self)] = result | ||||
|         result.widget = copy.deepcopy(self.widget, memo) | ||||
|         result.error_messages = self.error_messages.copy() | ||||
|         result.validators = self.validators[:] | ||||
|         return result | ||||
|  | ||||
|   | ||||
| @@ -3685,6 +3685,17 @@ Good luck picking a username that doesn't already exist.</p> | ||||
|         self.assertIsInstance(p.data, MultiValueDict) | ||||
|         self.assertIsInstance(p.files, MultiValueDict) | ||||
|  | ||||
|     def test_field_deep_copy_error_messages(self): | ||||
|         class CustomCharField(CharField): | ||||
|             def __init__(self, **kwargs): | ||||
|                 kwargs['error_messages'] = {'invalid': 'Form custom error message.'} | ||||
|                 super().__init__(**kwargs) | ||||
|  | ||||
|         field = CustomCharField() | ||||
|         field_copy = copy.deepcopy(field) | ||||
|         self.assertIsInstance(field_copy, CustomCharField) | ||||
|         self.assertIsNot(field_copy.error_messages, field.error_messages) | ||||
|  | ||||
|  | ||||
| class CustomRenderer(DjangoTemplates): | ||||
|     pass | ||||
|   | ||||
		Reference in New Issue
	
	Block a user