#3435 closed (fixed)
Can't serialize to file stream
Reported by: | Owned by: | Jacob | |
---|---|---|---|
Component: | Core (Serialization) | Version: | dev |
Severity: | Keywords: | ||
Cc: | Triage Stage: | Ready for checkin | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | yes |
Easy pickings: | no | UI/UX: | no |
Description
The stream argument to django.core.serializers.base.Serializer.serialize() does not work because serialize() calls self.stream.getvalue() to return the data; getvalue() is not part of the file protocol so this fails when stream is an HttpResponse, for example.
Also when using the stream argument for JSON serialization there is a failure in django.utils.simplejson.encoder.JSONEncoder.init() because the stream keyword argument is not accepted.
Attachments (1)
Change History (8)
comment:1 by , 18 years ago
Component: | Uncategorized → Serialization |
---|
comment:2 by , 18 years ago
Triage Stage: | Unreviewed → Accepted |
---|
comment:3 by , 18 years ago
Summary: | Can't serialize to stream → Can't serialize to file stream |
---|
by , 18 years ago
Attachment: | serialize_file_stream.patch added |
---|
comment:4 by , 18 years ago
Triage Stage: | Accepted → Ready for checkin |
---|
comment:5 by , 18 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
comment:6 by , 17 years ago
Patch needs improvement: | set |
---|
Wouldn't it be more appropriate not to return the serialized data if user supplied a stream to write to? This way, if the dataset is large, all of it wouldn't be in memory at the same time. If required, the user can get the data from the stream he supplied.
comment:7 by , 17 years ago
Please don't set needs_better_patch on a ticket that is already closed -- it's already been committed. If you don't want the data in memory, then don't pass in a stream with getvalue(). Files do not have getvalue, for example, so you're safe there.
This does mean that
serialize()
behaves differently with files, but if you have a file stream opened (for write) you can't read from it so there's no way forserialize()
to properly return the value anyway as far as I can tell.