﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
26040	Streaming Large CSV Files Example Incorrect	Philip Zerull	nobody	"Hi everyone,

The documentation has an example of how to stream large CSV files.

[https://docs.djangoproject.com/en/1.8/howto/outputting-csv/#streaming-large-csv-files]

This is great but unfortunately the solution is incorrect (at least in django 1.8 using python 3.4).

Per the documentation for the [https://docs.djangoproject.com/en/1.8/ref/request-response/#django.http.StreamingHttpResponse StreamingHTTPResponse class] ""It should be given an iterator that yields strings as content.""

but csvwriter.writerow returns None, not the result of the file.write call of the file passed to the csvwriter.  The Echo class provided in the example was a good idea but it doesn't appear to work.

An alternative solution that does work would be:


{{{
def streaming_csv_writer(rows_to_output):
    memory_file = StringIO()
    writer = csv.writer(memory_file)
    for row in rows_to_output:
        writer.writerow(row)
        memory_file.seek(0)
        yield memory_file.read()
        memory_file.truncate(0)

response = StreamingHTTPResponse(streaming_csv_writer(rows), ...)
}}}

I'm happy to patch this myself but I wanted to discuss it first before writing the patch to get some additional opinions and to try to discover a bit of the history of this documentation example (because I have a feeling it must have worked at some time in the past).

Django is a great framework and I'm truly grateful to the maintainers and contributors to the project.  You folks rock!"	Bug	closed	Documentation	1.8	Normal	invalid	csv streaming documentation bug	berker.peksag@…	Accepted	0	0	0	0	0	0
