#25725: UpdateCacheMiddleware can't cache a generator response
-------------------------------------+-------------------------------------
Reporter: dracos | Owner: nobody
Type: Uncategorized | Status: new
Component: Core (Cache system) | Version: 1.8
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by dracos):
timgraham: This actually was an edge case of something that would by
default use a StreamingHttpResponse, but would sometimes 404/error and
then it would switch to e.g. HttpResponseNotFound but still have a
generator-based content. Then a JSONP middleware would change the response
status to 200, and that would then try and be cached by the cache
middleware. We worked around it in the generic case by using a map(lambda
x:x, content) -
https://github.com/mysociety/mapit/commit/2a30c9eeaa939f14d5ada3bcaea71636c8cff7fb
- but also consuming the generator if it wasn't a 200 would have worked
too.
I do think the crash should be avoided, as the documentation says
"Finally, you can pass HttpResponse an iterator rather than strings.
HttpResponse will consume the iterator immediately, store its content as a
string, and discard it." - the generator is not being discarded, as it's
making it uncacheable, and it would be good if it could.
codingjoe: I would expect the response to be cached, not how to make it;
if I've passed an iterator to HttpResponse I expect it to have been
consumed and stored immediately as per the documentation.
--
Ticket URL: <https://code.djangoproject.com/ticket/25725#comment:4>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/064.d26e2d6ec14b815dc508cbf9bbda28ad%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.