diff --git a/django/forms/fields.py b/django/forms/fields.py index 03cd8af8d7..36ec634929 100644 --- a/django/forms/fields.py +++ b/django/forms/fields.py @@ -199,6 +199,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 diff --git a/tests/forms_tests/tests/test_forms.py b/tests/forms_tests/tests/test_forms.py index 45f5405fee..269567dac8 100644 --- a/tests/forms_tests/tests/test_forms.py +++ b/tests/forms_tests/tests/test_forms.py @@ -3685,6 +3685,17 @@ Good luck picking a username that doesn't already exist.

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