#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 | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+--------------------
As generator functions have a close method, an HTTPResponse using a
generator for its content dies when trying to be cached even though the
generator has been consumed and read by the content setter (because the
generator has been added to _closable_objects and that can't be cached).
Should the content setter of an HTTPResponse spot this and close/not add
to _closable_objects,or should it be documented that you can't use a
generator function with an HTTPResponse and have it be cached (even though
it's been read)?
{{{
from django.conf import settings
settings.configure(ALLOWED_HOSTS = ['*'])
from django.middleware import cache
from django import http
req = http.HttpRequest()
req.method = 'GET'
req.META = {'SERVER_NAME': 'localhost', 'SERVER_PORT':80}
resp = http.HttpResponse(x for x in range(1, 10))
cache.FetchFromCacheMiddleware().process_request(req)
cache.UpdateCacheMiddleware().process_response(req, resp)
}}}
gives
{{{
Can't pickle <type 'generator'>: attribute lookup __builtin__.generator
failed
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/25725>
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/049.28f87d97a7105980f9ebcb2c94672f0e%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.