From 7c70aa8f6376d761bd6d4bc075d232ee6e91f8f2 Mon Sep 17 00:00:00 2001 From: Hasan Ramezani Date: Tue, 8 Oct 2019 09:38:28 +0200 Subject: [3.0.x] Fixed #30839 -- Fixed Field.__deepcopy__() so forms don't share error messages. Backport of a28d1b38e55cf588cfaae97de6a575d5c9f90a96 from master --- tests/forms_tests/tests/test_forms.py | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'tests') 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 -- cgit v1.3