Opened 4 years ago

Closed 2 months 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: master
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 Changed 4 years ago by archivarius888

Description: modified (diff)

comment:2 Changed 4 years ago by Tim Graham

Could you provide the code to reproduce the error?

comment:3 Changed 4 years ago by archivarius888

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

comment:4 Changed 4 years ago by Huu Nguyen

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. Both ValidationError([]) and ValidationError({}) work just fine.

Last edited 4 years ago by Huu Nguyen (previous) (diff)

comment:5 Changed 4 years ago by archivarius888

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

comment:6 Changed 4 years ago by Tim Graham

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 Changed 3 years ago by Takis Issaris

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

comment:8 Changed 2 months ago by Adam Zapletal

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 Changed 2 months ago by Tim Graham

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