Opened 15 years ago

Closed 12 years ago

#11788 closed Bug (duplicate)

cache_page decorator doesn't work with HttpResponses whose content is an iterator

Reported by: Erik Allik Owned by: nobody
Component: Core (Cache system) Version: 1.1
Severity: Normal Keywords:
Cc: net147 Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

To reproduce:

@cache_page(60*15)
def foo(request):
    return HttpResponse(i for i in ('resp', 'onse'))

Responds with emptiness. Outcomment @cache_page(60*15) or replace i for i in ('resp', 'onse') with 'response' and it's fine.

The documentation for HttpResponse is clear about this: "content can be an iterator or a string."

Change History (11)

comment:1 by Russell Keith-Magee, 15 years ago

Resolution: invalid
Status: newclosed

I wasn't even aware that the docs ever claimed that a HttpResponse *could* be an iterator.

comment:2 by Carl Meyer, 15 years ago

They certainly do: http://docs.djangoproject.com/en/dev/ref/request-response/#passing-iterators

Perhaps at the least there ought to be a note there that this doesn't work with caching?

comment:3 by Erik Allik, 15 years ago

Resolution: invalid
Status: closedreopened

The docs are very clear about this: "Finally, you can pass HttpResponse an iterator rather than passing it hard-coded strings."

comment:4 by James Bennett, 15 years ago

The example you've given is a generator; so far as I'm aware we've never supported those in responses.

comment:5 by Alex Gaynor, 15 years ago

A generator is an iterator. If we want to say we support some iterators, but not all, that really needs to be explicitly documented (and it's going to confuse the hell out of people: myself included).

comment:6 by Russell Keith-Magee, 15 years ago

Triage Stage: UnreviewedAccepted

This isn't something that should be fixed in documentation. We need to work out why a generator doesn't cache properly - or why the caching process doesn't result in rolling out the generator.

comment:7 by Russell Keith-Magee, 15 years ago

#12214 is related to this problem.

comment:8 by Julien Phalip, 14 years ago

Component: Core frameworkCache system

comment:9 by Julien Phalip, 13 years ago

Severity: Normal
Type: Bug

comment:10 by net147, 13 years ago

Cc: net147 added
Easy pickings: unset
UI/UX: unset

comment:11 by Aymeric Augustin, 12 years ago

Resolution: duplicate
Status: reopenedclosed

This is an exact duplicate of #6527.

The problem is that cache_page will drain the iterator, leaving it empty for the actual rendering step.

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