#13093: cache_page decorator doesn't work on callable classes
-----------------------------------+----------------------------------------
          Reporter:  russellm      |         Owner:  nobody  
            Status:  new           |     Milestone:  1.2     
         Component:  Cache system  |       Version:  1.2-beta
        Resolution:                |      Keywords:          
             Stage:  Accepted      |     Has_patch:  0       
        Needs_docs:  0             |   Needs_tests:  0       
Needs_better_patch:  0             |  
-----------------------------------+----------------------------------------
Changes (by russellm):

  * needs_better_patch:  => 0
  * stage:  Unreviewed => Accepted
  * needs_tests:  => 0
  * needs_docs:  => 0

Old description:

> The cache_page() decorator works fine on views, but fails if you use it
> on a callable class::
> class:
> {{{
> class MyView(object):
>     def __call__(self, request):
>         return HttpResponse()
> }}}
>
> If you try to wrap this view in urls.py ({{{ cache_page(MyView(), 60)
> }}}), you get an error saying "MyView doesn't have attribute __name__".
> cache_page uses the __name__ attribute to build a cache key, but classes
> dont have a __name__ attribute. cache_page should also check for
> __class__.__name__ (or some similar key with a per-instance feature) to
> allow for wrapping callable classes.
>
> This is a problem for 1.2, because feed views have been moved to a class-
> based structure, so it is no longer possible to cache feed views using
> cache_page().

New description:

 The cache_page() decorator works fine on views, but fails if you use it on
 a callable class::
 {{{
 class MyView(object):
     def __call__(self, request):
         return HttpResponse()
 }}}

 If you try to wrap this view in urls.py ({{{ cache_page(MyView(), 60)
 }}}), you get an error saying "MyView doesn't have attribute !__name!__".
 cache_page uses the !__name!__ attribute to build a cache key, but classes
 dont have a !__name!__ attribute. cache_page should also check for
 !__class!__.!__name!__ (or some similar key with a per-instance feature)
 to allow for wrapping callable classes.

 This is a problem for 1.2, because feed views have been moved to a class-
 based structure, so it is no longer possible to cache feed views using
 cache_page().

Comment:

 Forgot to mention: Thanks to  Brian Neal for the report.

-- 
Ticket URL: <http://code.djangoproject.com/ticket/13093#comment:1>
Django <http://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 post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.

Reply via email to