Opened 7 years ago

Closed 4 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 Changed 7 years ago by Russell Keith-Magee

Resolution: invalid
Status: newclosed

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

comment:2 Changed 7 years ago by Carl Meyer

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 Changed 7 years ago by Erik Allik

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 Changed 7 years ago by James Bennett

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

comment:5 Changed 7 years ago by Alex Gaynor

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 Changed 7 years ago by Russell Keith-Magee

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 Changed 7 years ago by Russell Keith-Magee

#12214 is related to this problem.

comment:8 Changed 6 years ago by Julien Phalip

Component: Core frameworkCache system

comment:9 Changed 6 years ago by Julien Phalip

Severity: Normal
Type: Bug

comment:10 Changed 5 years ago by net147

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

comment:11 Changed 4 years ago by Aymeric Augustin

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