Opened 6 years ago

Closed 3 years ago

#11788 closed Bug (duplicate)

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

Reported by: RaceCondition 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 6 years ago by russellm

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Resolution set to invalid
  • Status changed from new to closed

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

comment:2 Changed 6 years ago by carljm

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 6 years ago by RaceCondition

  • Resolution invalid deleted
  • Status changed from closed to reopened

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

comment:4 Changed 6 years ago by ubernostrum

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

comment:5 Changed 6 years ago by Alex

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 6 years ago by russellm

  • Triage Stage changed from Unreviewed to 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:7 Changed 5 years ago by russellm

#12214 is related to this problem.

comment:8 Changed 4 years ago by julien

  • Component changed from Core framework to Cache system

comment:9 Changed 4 years ago by julien

  • Severity set to Normal
  • Type set to Bug

comment:10 Changed 4 years ago by net147

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

comment:11 Changed 3 years ago by aaugustin

  • Resolution set to duplicate
  • Status changed from reopened to 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.

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