diff --git a/django/forms/utils.py b/django/forms/utils.py index 14253f36fe..f5fc0515a5 100644 --- a/django/forms/utils.py +++ b/django/forms/utils.py @@ -138,6 +138,15 @@ class ErrorList(UserList, list): return list(error)[0] return force_text(error) + def __reduce_ex__(self, *args, **kwargs): + # The `list` reduce function returns an iterator as the fourth element + # that is normally used for repopulating. Since we only inherit from + # `list` for `isinstance` backward compatibility (Refs #17413) we + # nullify this iterator as it would otherwise result in duplicate + # entries. (Refs #23594) + info = super(UserList, self).__reduce_ex__(*args, **kwargs) + return info[:3] + (None, None) + # Utilities for time zone support in DateTimeField et al. diff --git a/docs/releases/1.7.1.txt b/docs/releases/1.7.1.txt index c481a4b4c4..f743447d56 100644 --- a/docs/releases/1.7.1.txt +++ b/docs/releases/1.7.1.txt @@ -89,3 +89,5 @@ Bugfixes * Fixed ``MigrationWriter`` to handle builtin types without imports (:ticket:`23560`). + +* Fixed ``deepcopy`` on ``ErrorList`` (:ticket:`23594`). diff --git a/tests/forms_tests/tests/test_util.py b/tests/forms_tests/tests/test_util.py index d271d784c9..68ecd50e99 100644 --- a/tests/forms_tests/tests/test_util.py +++ b/tests/forms_tests/tests/test_util.py @@ -1,6 +1,8 @@ # -*- coding: utf-8 -*- from __future__ import unicode_literals +import copy + from django.core.exceptions import ValidationError from django.forms.utils import flatatt, ErrorDict, ErrorList from django.test import TestCase @@ -69,3 +71,24 @@ class FormsUtilTestCase(TestCase): '