Opened 15 years ago

Closed 15 years ago

Last modified 15 years ago

#3435 closed (fixed)

Can't serialize to file stream

Reported by: kent@… 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


The stream argument to django.core.serializers.base.Serializer.serialize() does not work because serialize() calls 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)

serialize_file_stream.patch (1.3 KB) - added by Chris Beaven 15 years ago.

Download all attachments as: .zip

Change History (8)

comment:1 Changed 15 years ago by anonymous

Component: UncategorizedSerialization

comment:2 Changed 15 years ago by Simon G. <dev@…>

Triage Stage: UnreviewedAccepted

comment:3 Changed 15 years ago by Chris Beaven

Summary: Can't serialize to streamCan't serialize to file stream

Changed 15 years ago by Chris Beaven

Attachment: serialize_file_stream.patch added

comment:4 Changed 15 years ago by Chris Beaven

Triage Stage: AcceptedReady for checkin

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 for serialize() to properly return the value anyway as far as I can tell.

comment:5 Changed 15 years ago by Malcolm Tredinnick

Resolution: fixed
Status: newclosed

(In [5075]) Fixed #3435 -- Fixed serializing to a file stream. Patch from SmileyChris.

comment:6 Changed 15 years ago by ramashish.lists@…

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 Changed 15 years ago by Malcolm Tredinnick

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.

Note: See TracTickets for help on using tickets.
Back to Top