[Django] #24008: ValidationError crashes if initialised with a list that includes a ValidationError instance initialised with a dict.

41 views
Skip to first unread message

Django

unread,
Dec 17, 2014, 8:47:46 AM12/17/14
to django-...@googlegroups.com
#24008: ValidationError crashes if initialised with a list that includes a
ValidationError instance initialised with a dict.
-------------------------------+--------------------
Reporter: seansean49 | Owner: nobody
Type: Uncategorized | Status: new
Component: Uncategorized | Version: 1.6
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------
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>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Dec 17, 2014, 9:55:11 AM12/17/14
to django-...@googlegroups.com
#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

unread,
Dec 21, 2014, 3:47:45 PM12/21/14
to django-...@googlegroups.com
#24008: ValidationError crashes if initialised with a list that includes a
ValidationError instance initialised with a dict.
------------------------------+-------------------------------------
Reporter: seansean49 | Owner: GreyZmeem
Type: Bug | Status: assigned

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 GreyZmeem):

* status: new => assigned
* owner: nobody => GreyZmeem


--
Ticket URL: <https://code.djangoproject.com/ticket/24008#comment:2>

Django

unread,
Dec 24, 2014, 6:47:01 PM12/24/14
to django-...@googlegroups.com
#24008: ValidationError crashes if initialised with a list that includes a
ValidationError instance initialised with a dict.
------------------------------+-------------------------------------
Reporter: seansean49 | Owner: GreyZmeem
Type: Bug | Status: assigned
Component: Core (Other) | Version: 1.7
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
------------------------------+-------------------------------------
Changes (by timgraham):

* needs_better_patch: 0 => 1
* has_patch: 0 => 1


--
Ticket URL: <https://code.djangoproject.com/ticket/24008#comment:3>

Django

unread,
Dec 31, 2014, 2:46:09 PM12/31/14
to django-...@googlegroups.com
#24008: ValidationError crashes if initialised with a list that includes a
ValidationError instance initialised with a dict.
-------------------------------------+-------------------------------------

Reporter: seansean49 | Owner: GreyZmeem
Type: Bug | Status: assigned
Component: Core (Other) | Version: 1.7
Severity: Normal | Resolution:
Keywords: | Triage Stage: Ready for
| checkin

Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by timgraham):

* needs_better_patch: 1 => 0
* stage: Accepted => Ready for checkin


--
Ticket URL: <https://code.djangoproject.com/ticket/24008#comment:4>

Django

unread,
Dec 31, 2014, 2:46:19 PM12/31/14
to django-...@googlegroups.com
#24008: ValidationError crashes if initialised with a list that includes a
ValidationError instance initialised with a dict.
-------------------------------------+-------------------------------------
Reporter: seansean49 | Owner: GreyZmeem
Type: Bug | Status: closed

Component: Core (Other) | Version: 1.7
Severity: Normal | Resolution: fixed

Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham <timograham@…>):

* status: assigned => closed
* resolution: => fixed


Comment:

In [changeset:"7a878ca5cb50ad65fc465cb263a44cc93629f75c"]:
{{{
#!CommitTicketReference repository=""
revision="7a878ca5cb50ad65fc465cb263a44cc93629f75c"
Fixed #24008 -- Fixed ValidationError crash with list of dicts.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/24008#comment:5>

Django

unread,
Dec 31, 2014, 4:51:38 PM12/31/14
to django-...@googlegroups.com
#24008: ValidationError crashes if initialised with a list that includes a
ValidationError instance initialised with a dict.
-------------------------------------+-------------------------------------
Reporter: seansean49 | Owner: GreyZmeem
Type: Bug | Status: closed
Component: Core (Other) | Version: 1.7
Severity: Normal | Resolution: fixed
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Tim Graham <timograham@…>):

In [changeset:"8de2a44064ca11749579a5887f59821fa35e1fdc"]:
{{{
#!CommitTicketReference repository=""
revision="8de2a44064ca11749579a5887f59821fa35e1fdc"
[1.7.x] Fixed #24008 -- Fixed ValidationError crash with list of dicts.

Backport of 7a878ca5cb50ad65fc465cb263a44cc93629f75c from master
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/24008#comment:6>

Reply all
Reply to author
Forward
0 new messages