Last active
December 29, 2015 18:09
-
-
Save loic/7708825 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 62c4d0b..418eaab 100644 | |
--- a/django/core/exceptions.py | |
+++ b/django/core/exceptions.py | |
@@ -3,6 +3,7 @@ Global Django exception and warning classes. | |
""" | |
from functools import reduce | |
import operator | |
+import copy | |
from django.utils.encoding import force_text | |
@@ -85,7 +86,15 @@ class ValidationError(Exception): | |
of ValidationError with its `error_list` or `error_dict` attribute set. | |
""" | |
if isinstance(message, ValidationError): | |
- self.__dict__.update(message.__dict__) | |
+ if hasattr(message, 'error_dict'): | |
+ self.error_dict = copy.copy(message.error_dict) | |
+ elif not hasattr(message, 'message'): | |
+ self.error_list = copy.copy(message.error_list) | |
+ else: | |
+ self.message = message.message | |
+ self.code = message.code | |
+ self.params = copy.copy(message.params) | |
+ self.error_list = [self] | |
elif isinstance(message, dict): | |
self.error_dict = {} | |
diff --git a/tests/forms_tests/tests/test_forms.py b/tests/forms_tests/tests/test_forms.py | |
index 7f30b0e..faccda1 100644 | |
--- a/tests/forms_tests/tests/test_forms.py | |
+++ b/tests/forms_tests/tests/test_forms.py | |
@@ -693,6 +693,7 @@ class FormsTestCase(TestCase): | |
self.add_error('password1', 'Forbidden value 2.') | |
if self.cleaned_data.get('password2') == 'FORBIDDEN_VALUE2': | |
self.add_error('password2', 'Forbidden value 2.') | |
+ raise ValidationError("I'm a non field error.") | |
return self.cleaned_data | |
@@ -729,7 +730,7 @@ class FormsTestCase(TestCase): | |
self.assertEqual(f.errors['password2'], ['Forbidden value.']) | |
f = UserRegistration({'username': 'adrian', 'password1': 'FORBIDDEN_VALUE2', 'password2': 'FORBIDDEN_VALUE2'}, auto_id=False) | |
- self.assertEqual(f.errors['__all__'], ['Forbidden value 2.']) | |
+ self.assertEqual(f.errors['__all__'], ['Forbidden value 2.', "I'm a non field error."]) | |
self.assertEqual(f.errors['password1'], ['Forbidden value 2.']) | |
self.assertEqual(f.errors['password2'], ['Forbidden value 2.']) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment