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 , 15 years ago
Resolution: | → invalid |
---|---|
Status: | new → closed |
comment:2 by , 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 , 15 years ago
Resolution: | invalid |
---|---|
Status: | closed → reopened |
The docs are very clear about this: "Finally, you can pass HttpResponse an iterator rather than passing it hard-coded strings."
comment:4 by , 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 , 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 , 15 years ago
Triage Stage: | Unreviewed → Accepted |
---|
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:8 by , 14 years ago
Component: | Core framework → Cache system |
---|
comment:9 by , 13 years ago
Severity: | → Normal |
---|---|
Type: | → Bug |
comment:10 by , 13 years ago
Cc: | added |
---|---|
Easy pickings: | unset |
UI/UX: | unset |
comment:11 by , 12 years ago
Resolution: | → duplicate |
---|---|
Status: | reopened → closed |
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.
I wasn't even aware that the docs ever claimed that a HttpResponse *could* be an iterator.