#19159 closed Bug (invalid)
loaddata reports DeserializationError instead of MemoryError
| Reported by: | Owned by: | nobody | |
|---|---|---|---|
| Component: | Core (Serialization) | Version: | dev |
| Severity: | Normal | Keywords: | |
| Cc: | Triage Stage: | Accepted | |
| Has patch: | yes | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
The command manage.py loaddata data.json errors with DeserializationError instead of MemoryError.
files:
../lib/python2.7/site-packages/django/core/serializers/json.py /usr/lib/python2.7/json/__init__.py
relevant code is simplejson.load(stream) inside the try:
def Deserializer(stream_or_string, **options):
"""
Deserialize a stream or string of JSON data.
"""
if isinstance(stream_or_string, basestring):
stream = StringIO(stream_or_string)
else:
stream = stream_or_string
try:
for obj in PythonDeserializer(simplejson.load(stream), **options):
yield obj
except GeneratorExit:
raise
except Exception, e:
# Map to deserializer error
raise DeserializationError(e)
Change History (10)
comment:1 by , 13 years ago
| Component: | Uncategorized → Core (Serialization) |
|---|
comment:2 by , 13 years ago
comment:3 by , 13 years ago
i think there's too much going on in the try statement:
for obj in PythonDeserializer(simplejson.load(stream), **options):
yield obj
the error arises from simplejson.load(stream) when reading a large json file from disk during fp.read().
comment:4 by , 13 years ago
| Triage Stage: | Unreviewed → Accepted |
|---|
comment:6 by , 13 years ago
No, #5423 is fixing dumpdata, this ticket is about loaddata. The problem with loaddata is that it would be very difficult to incrementally read the file.
comment:7 by , 11 years ago
comment:8 by , 5 years ago
| Has patch: | set |
|---|---|
| Version: | 1.4 → dev |
PR on the assumption we don't want to wrap MemoryError. If we do want to wrap it, we're already chaining the exception with raise from so we can just close the ticket.
comment:9 by , 5 years ago
| Resolution: | → invalid |
|---|---|
| Status: | new → closed |
MemoryError is not wrapped anymore because we no longer use StringIO or BytesIO, and MemoryError is raised by .read() (see 7d0f8831922535502569a5dda989dde339b4e491):
File "django/django/core/serializers/json.py", line 65, in Deserializer
stream_or_string = stream_or_string.read()
MemoryError: Problem installing fixture 'mydump.json'
comment:10 by , 5 years ago
I'm not so sure that MemoryError is only triggered by read(), but let's see how it goes and if the issue happens again in the future.
In Python 3 this could be written as
raise DeserializationError from e, but I don't see a better equivalent in Python 2.