Opened 18 years ago

Closed 18 years ago

Last modified 17 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

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)

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

Download all attachments as: .zip

Change History (8)

comment:1 by anonymous, 18 years ago

Component: UncategorizedSerialization

comment:2 by Simon G. <dev@…>, 18 years ago

Triage Stage: UnreviewedAccepted

comment:3 by Chris Beaven, 18 years ago

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

by Chris Beaven, 18 years ago

Attachment: serialize_file_stream.patch added

comment:4 by Chris Beaven, 18 years ago

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 by Malcolm Tredinnick, 18 years ago

Resolution: fixed
Status: newclosed

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

comment:6 by ramashish.lists@…, 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 Malcolm Tredinnick, 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.

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