Opened 6 years ago

Closed 6 years ago

Last modified 5 years ago

#15012 closed (fixed)

cache_page decorator (memcached) fails with Django 1.3b1 (can't pickle Input object)

Reported by: vkojouharov@… Owned by: nobody
Component: Generic views Version: 1.3-beta
Severity: Keywords: pickle, memcached, blocker
Cc: Triage Stage: Design decision needed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:



I'm consistently getting an error with each request after upgrading from Django 1.3a1 to 1.3b1.
The settings aren't changed after the upgrade, and if I remove the cache_page decorator, everything is back on track. The url in question is pasted below:

url(r'^/?$', cache_page(views.IndexView.as_view(), timeout), name='main_index')

Attachments (4)

cache_page.error (10.7 KB) - added by vkojouharov@… 6 years ago.
traceback, META and settings
cache_page_test.tar.bz2 (7.1 KB) - added by urandom 6 years ago.
a simple project which causes the error
t15012.diff (2.6 KB) - added by russellm 6 years ago.
Test case demonstrating the problem
15012.diff (5.3 KB) - added by Joshua "jag" Ginsberg <jag@…> 6 years ago.
Patch to fix the issue (includes previously attached tests)

Download all attachments as: .zip

Change History (11)

Changed 6 years ago by vkojouharov@…

traceback, META and settings

comment:1 Changed 6 years ago by russellm

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

We're going to need a bit more than a stack trace. We have an test suite checking cache_page, and those tests are passing. There is clearly something special about your page.

We need a reproducible test case to be able to accept this bug. Please reopen if you can provide a simple view that fails in the way you describe.

Changed 6 years ago by urandom

a simple project which causes the error

comment:2 Changed 6 years ago by urandom

  • Resolution worksforme deleted
  • Status changed from closed to reopened

I've attached a generic django project, with an app that only contains 1 view that is cached. The only setting that was changed was the cache setting. The apache directory contains the wsgi and virtualhost configs for apache.

Running this through apache reproduces this error. Interestingly, running it through the internal server produces a different error, which is still connected to the cache_page:

a class that defines __slots__ without defining __getstate__ cannot be pickled

comment:3 Changed 6 years ago by russellm

  • Component changed from Cache system to Generic views
  • Triage Stage changed from Unreviewed to Design decision needed

Ah. This is a bit of a problem. The introduction of TemplateResponse means that the cache page decorator can't be used on Template Views. Which is a fairly major omission.

We either need to make generic views use normal responses (and make TemplateResponse an available option), or we need to find a way to let decorators (especially the cache decorator) play nice with TemplateResponse.

This is definitely a 1.3 blocker.

Changed 6 years ago by russellm

Test case demonstrating the problem

comment:4 Changed 6 years ago by russellm

  • Keywords blocker added

Changed 6 years ago by Joshua "jag" Ginsberg <jag@…>

Patch to fix the issue (includes previously attached tests)

comment:5 Changed 6 years ago by Joshua "jag" Ginsberg <jag@…>

  • Has patch set

Attached a patch - it puts pre_render and post_render callbacks into the TemplateResponse and modifies the cache middleware, in the face of a TemplateResponse, to register a callback on the TemplateResponse to store the final rendered copy in cache. I included russelm's test cases in the patch.


comment:6 Changed 6 years ago by russellm

  • Resolution set to fixed
  • Status changed from reopened to closed

(In [15295]) Fixed #15012 -- Added post-rendering callbacks to TemplateResponse so that decorators (in particular, the cache decorator) can defer processing until after rendering has occurred. Thanks to Joshua Ginsberg for the draft patch.

comment:7 Changed 5 years ago by jacob

  • milestone 1.3 deleted

Milestone 1.3 deleted

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