Opened 10 years ago

Closed 6 years ago

#23976 closed Cleanup/optimization (fixed)

ValidationError crashes if initialized with a list of empty dicts

Reported by: archivarius888 Owned by: nobody
Component: Core (Other) Version: dev
Severity: Normal Keywords: exceptions, ValidationError
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by archivarius888)

Redefinition variable message by django/django/core/exceptions.py
line 114, for message in message:

below line, 116:

                if not isinstance(message, ValidationError):
                    message = ValidationError(message)
                self.error_list.extend(message.error_list)

if message isinstance of dict: AttributeError: 'ValidationError' object has no attribute 'error_list'

Change History (9)

comment:1 by archivarius888, 10 years ago

Description: modified (diff)

comment:2 by Tim Graham, 10 years ago

Could you provide the code to reproduce the error?

comment:3 by archivarius888, 10 years ago

>>> from django.core.exceptions import ValidationError
>>> ValidationError([{}])

comment:4 by Huu Nguyen, 10 years ago

Under what circumstances does this exception get thrown? From the definition of message, it doesn't appear that [{}] is a valid form of message. If message does take that form somehow, then that's a separate bug.

Version 0, edited 10 years ago by Huu Nguyen (next)

comment:5 by archivarius888, 10 years ago

Yeap, I just code would be better. And the user can do anything.

comment:6 by Tim Graham, 10 years ago

Component: Core (Serialization)Core (Other)
Severity: Release blockerNormal
Summary: ValidationError by list argumentValidationError crashes if initialized with a list of empty dicts
Triage Stage: UnreviewedAccepted
Type: BugCleanup/optimization

We could at least not crash so obscurely I suppose.

comment:7 by Takis Issaris, 9 years ago

Could not reproduce using current Django master on Python 3.4.1 on OSX 10.10.4.

comment:8 by Adam Zapletal, 6 years ago

I've confirmed that the crash no longer happens on both v2.0.7 and master on Mac OS 10.13.5 with Python 3.7.0:

In [1]: import django

In [2]: django.__version__
Out[2]: '2.0.7'

In [3]: from django.core.exceptions import ValidationError

In [4]: ValidationError([{}])
Out[4]: ValidationError([])
In [1]: import django

In [2]: django.__version__
Out[2]: '2.2.dev20180711212029'

In [3]: from django.core.exceptions import ValidationError

In [4]: ValidationError([{}])
Out[4]: ValidationError([])

Can this ticket be closed?

comment:9 by Tim Graham, 6 years ago

Resolution: fixed
Status: newclosed
Note: See TracTickets for help on using tickets.
Back to Top