Created
June 30, 2014 11:56
-
-
Save loic/adf447623b4e25c97c7e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/django/core/exceptions.py b/django/core/exceptions.py | |
index cf4aea0..2f02c14 100644 | |
--- a/django/core/exceptions.py | |
+++ b/django/core/exceptions.py | |
@@ -141,9 +141,9 @@ class ValidationError(Exception): | |
for field, errors in self.error_dict.items(): | |
error_dict.setdefault(field, []).extend(errors) | |
else: | |
- error_dict = self.error_dict | |
+ error_dict.update(self.error_dict) | |
else: | |
- error_dict[NON_FIELD_ERRORS] = self.error_list | |
+ error_dict.setdefault(NON_FIELD_ERRORS, []).extend(self.error_list) | |
return error_dict | |
def __iter__(self): | |
diff --git a/tests/forms_tests/tests/test_forms.py b/tests/forms_tests/tests/test_forms.py | |
index 985ff8e..6782c80 100644 | |
--- a/tests/forms_tests/tests/test_forms.py | |
+++ b/tests/forms_tests/tests/test_forms.py | |
@@ -740,6 +740,24 @@ class FormsTestCase(TestCase): | |
with six.assertRaisesRegex(self, ValueError, "has no field named"): | |
f.add_error('missing_field', 'Some error.') | |
+ def test_backwards_compat_update_error_dict(self): | |
+ class CodeForm(Form): | |
+ code = CharField(max_length=10) | |
+ | |
+ def clean(self): | |
+ try: | |
+ raise ValidationError({ | |
+ 'code': [ValidationError('Code error')] | |
+ }) | |
+ except ValidationError as e: | |
+ self._errors = e.update_error_dict(self._errors) | |
+ for field, error_list in self._errors.items(): | |
+ if not isinstance(error_list, self.error_class): | |
+ self._errors[field] = self.error_class(error_list) | |
+ | |
+ form = CodeForm({'code': 'hello'}) | |
+ self.assertEqual(dict(form.errors), {'code': ['Code error']}) | |
+ | |
def test_has_error(self): | |
class UserRegistration(Form): | |
username = CharField(max_length=10) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment