Opened 10 years ago

Closed 9 years ago

Last modified 9 years ago

#3435 closed (fixed)

Can't serialize to file stream

Reported by: kent@… Owned by: jacob
Component: Core (Serialization) Version: master
Severity: Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: yes
Easy pickings: UI/UX:


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 SmileyChris 9 years ago.

Download all attachments as: .zip

Change History (8)

comment:1 Changed 10 years ago by anonymous

  • Component changed from Uncategorized to Serialization
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

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

  • Triage Stage changed from Unreviewed to Accepted

comment:3 Changed 9 years ago by SmileyChris

  • Summary changed from Can't serialize to stream to Can't serialize to file stream

Changed 9 years ago by SmileyChris

comment:4 Changed 9 years ago by SmileyChris

  • Triage Stage changed from Accepted to Ready 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 9 years ago by mtredinnick

  • Resolution set to fixed
  • Status changed from new to closed

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

comment:6 Changed 9 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 9 years ago by mtredinnick

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