Django

Code

Ticket #3435 (closed: fixed)

Opened 2 years ago

Last modified 2 years ago

Can't serialize to file stream

Reported by: kent@kentsjohnson.com Assigned to: jacob
Milestone: Component: Serialization
Version: SVN Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: 0 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 1

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

serialize_file_stream.patch (1.3 kB) - added by SmileyChris on 03/20/07 17:36:51.

Change History

02/05/07 10:57:37 changed by anonymous

  • needs_better_patch changed.
  • component changed from Uncategorized to Serialization.
  • needs_tests changed.
  • needs_docs changed.

02/25/07 23:37:28 changed by Simon G. <dev@simon.net.nz>

  • stage changed from Unreviewed to Accepted.

03/20/07 16:37:59 changed by SmileyChris

  • summary changed from Can't serialize to stream to Can't serialize to file stream.

03/20/07 17:36:51 changed by SmileyChris

  • attachment serialize_file_stream.patch added.

03/20/07 17:38:33 changed by SmileyChris

  • 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.

04/25/07 05:12:05 changed by mtredinnick

  • status changed from new to closed.
  • resolution set to fixed.

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

05/23/07 00:23:44 changed by ramashish.lists@gmail.com

  • needs_better_patch set to 1.

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.

05/23/07 00:28:25 changed 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.


Add/Change #3435 (Can't serialize to file stream)




Change Properties
Action