Fixed #24008 -- Fixed ValidationError crash with list of dicts.
This commit is contained in:
parent
a1487deebf
commit
7a878ca5cb
|
@ -115,6 +115,9 @@ class ValidationError(Exception):
|
||||||
# Normalize plain strings to instances of ValidationError.
|
# Normalize plain strings to instances of ValidationError.
|
||||||
if not isinstance(message, ValidationError):
|
if not isinstance(message, ValidationError):
|
||||||
message = ValidationError(message)
|
message = ValidationError(message)
|
||||||
|
if hasattr(message, 'error_dict'):
|
||||||
|
self.error_list.extend(sum(message.error_dict.values(), []))
|
||||||
|
else:
|
||||||
self.error_list.extend(message.error_list)
|
self.error_list.extend(message.error_list)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -186,3 +186,6 @@ Bugfixes
|
||||||
|
|
||||||
* Restored the ability to use more than five levels of subqueries
|
* Restored the ability to use more than five levels of subqueries
|
||||||
(:ticket:`23758`).
|
(:ticket:`23758`).
|
||||||
|
|
||||||
|
* Fixed crash when ``ValidationError`` is initialized with a ``ValidationError``
|
||||||
|
that is initialized with a dictionary (:ticket:`24008`).
|
||||||
|
|
|
@ -65,9 +65,31 @@ class FormsUtilsTestCase(TestCase):
|
||||||
self.assertHTMLEqual(str(ErrorList(ValidationError(["Error one.", "Error two."]).messages)),
|
self.assertHTMLEqual(str(ErrorList(ValidationError(["Error one.", "Error two."]).messages)),
|
||||||
'<ul class="errorlist"><li>Error one.</li><li>Error two.</li></ul>')
|
'<ul class="errorlist"><li>Error one.</li><li>Error two.</li></ul>')
|
||||||
|
|
||||||
|
# Can take a dict.
|
||||||
|
self.assertHTMLEqual(
|
||||||
|
str(ErrorList(sorted(ValidationError({'error_1': "1. Error one.", 'error_2': "2. Error two."}).messages))),
|
||||||
|
'<ul class="errorlist"><li>1. Error one.</li><li>2. Error two.</li></ul>'
|
||||||
|
)
|
||||||
|
|
||||||
# Can take a mixture in a list.
|
# Can take a mixture in a list.
|
||||||
self.assertHTMLEqual(str(ErrorList(ValidationError(["First error.", "Not \u03C0.", ugettext_lazy("Error.")]).messages)),
|
self.assertHTMLEqual(
|
||||||
'<ul class="errorlist"><li>First error.</li><li>Not π.</li><li>Error.</li></ul>')
|
str(ErrorList(sorted(ValidationError([
|
||||||
|
"1. First error.",
|
||||||
|
"2. Not \u03C0.",
|
||||||
|
ugettext_lazy("3. Error."),
|
||||||
|
{
|
||||||
|
'error_1': "4. First dict error.",
|
||||||
|
'error_2': "5. Second dict error.",
|
||||||
|
},
|
||||||
|
]).messages))),
|
||||||
|
'<ul class="errorlist">'
|
||||||
|
'<li>1. First error.</li>'
|
||||||
|
'<li>2. Not π.</li>'
|
||||||
|
'<li>3. Error.</li>'
|
||||||
|
'<li>4. First dict error.</li>'
|
||||||
|
'<li>5. Second dict error.</li>'
|
||||||
|
'</ul>'
|
||||||
|
)
|
||||||
|
|
||||||
@python_2_unicode_compatible
|
@python_2_unicode_compatible
|
||||||
class VeryBadError:
|
class VeryBadError:
|
||||||
|
|
Loading…
Reference in New Issue