#24008: ValidationError crashes if initialised with a list that includes a
ValidationError instance initialised with a dict.
------------------------------+------------------------------------
Reporter: seansean49 | Owner: nobody
Type: Bug | Status: new
Component: Core (Other) | Version: 1.7
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
------------------------------+------------------------------------
Changes (by timgraham):
* needs_better_patch: => 0
* component: Uncategorized => Core (Other)
* needs_tests: => 0
* version: 1.6 => 1.7
* needs_docs: => 0
* type: Uncategorized => Bug
* stage: Unreviewed => Accepted
Old description:
> According to the documentation, ValidationError can be initialised with a
> list of ValidationError instances. However, if the list includes a
> ValidationError that was initialised with a dictionary then it crashes
> with the following error: 'ValidationError' object has no attribute
> 'error_list'.
>
> This bug would occur if someone wanted to raise a ValidationError with a
> set of field errors together with one or more non-field errors for
> example.
>
> For example:
>
> >>> from django.core.exceptions import ValidationError
> >>> ValidationError([ValidationError({'age', 'age cannot be negative'}),
> ValidationError('Some other error')])
>
> The problem is caused because when a ValidationError instance is
> initialised with a dictionary, its error_list attribute is not set
> (instead error_dict is set) but a ValidationError that is initialised
> with a list tries to compile a flattened list of all errors using this
> attribute from each list element. Either ValidationError should be
> modified to accept a mixture of field and non-field errors (appears to me
> to be the best solution) or the documentation and error message should be
> changed to make usage clear.
>
> Related to https://code.djangoproject.com/ticket/23976
New description:
According to the documentation, ValidationError can be initialised with a
list of ValidationError instances. However, if the list includes a
ValidationError that was initialised with a dictionary then it crashes
with the following error: 'ValidationError' object has no attribute
'error_list'.
This bug would occur if someone wanted to raise a ValidationError with a
set of field errors together with one or more non-field errors for
example.
For example:
{{{
>>> from django.core.exceptions import ValidationError
>>> ValidationError([ValidationError({'age', 'age cannot be negative'}),
ValidationError('Some other error')])
}}}
The problem is caused because when a ValidationError instance is
initialised with a dictionary, its error_list attribute is not set
(instead error_dict is set) but a ValidationError that is initialised with
a list tries to compile a flattened list of all errors using this
attribute from each list element. Either ValidationError should be
modified to accept a mixture of field and non-field errors (appears to me
to be the best solution) or the documentation and error message should be
changed to make usage clear.
Related to https://code.djangoproject.com/ticket/23976
--
--
Ticket URL: <https://code.djangoproject.com/ticket/24008#comment:1>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/068.6ebb05e70fc2016d1ce11dc7803e89e3%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.