Opened 11 years ago
Closed 7 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 )
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 , 11 years ago
| Description: | modified (diff) | 
|---|
comment:2 by , 11 years ago
comment:3 by , 11 years ago
>>> from django.core.exceptions import ValidationError
>>> ValidationError([{}])
comment:4 by , 11 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. Both ValidationError([]) and ValidationError({}) work just fine.
comment:6 by , 11 years ago
| Component: | Core (Serialization) → Core (Other) | 
|---|---|
| Severity: | Release blocker → Normal | 
| Summary: | ValidationError by list argument → ValidationError crashes if initialized with a list of empty dicts | 
| Triage Stage: | Unreviewed → Accepted | 
| Type: | Bug → Cleanup/optimization | 
We could at least not crash so obscurely I suppose.
comment:7 by , 10 years ago
Could not reproduce using current Django master on Python 3.4.1 on OSX 10.10.4.
comment:8 by , 7 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 , 7 years ago
| Resolution: | → fixed | 
|---|---|
| Status: | new → closed | 
Could you provide the code to reproduce the error?