Opened 18 years ago

Closed 17 years ago

#2567 closed defect (duplicate)

cache_page works as wrapper function, not as decorator

Reported by: Jaroslaw Zabiello <hipertracker@…> Owned by: Jacob
Component: Core (Cache system) Version: dev
Severity: normal Keywords: cache win32 linux freebsd
Cc: ca.dein@… Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

There are severe issues with cache settings and implementations for *Windows* (it was tested on Windows XP Pro SP2 with fresh SVN version of Django). Eg.

for

CACHE_BACKEND = 'file:///c:/tmp/cache'

the following error is displayed:

EnvironmentError at /test/
Cache directory '/c:/tmp/cache' does not exist and could not be created'

So I switched to database (table cache is existing of course)

CACHE_BACKEND = 'db://cache' 
CACHE_MIDDLEWARE_SECONDS = 30

But then I have another error:

AttributeError at /test/
'function' object has no attribute 'method'
Request Method: 	GET
Request URL: 	http://localhost:8000/test/
Exception Type: 	AttributeError
Exception Value: 	'function' object has no attribute 'method'
Exception Location: 	c:\opt\python24\lib\site-packages\Django-0.95-py2.4.egg\django\middleware\cache.py in process_request, line 47

Change History (13)

comment:1 by Malcolm Tredinnick, 18 years ago

priority: highestnormal
Severity: blockernormal

In the first case, you have the URI specified incorrectly. The triple-forward-slash example in the docs is for a Unix-like filesystem. In Windows, I believe you want file://c:/... (you can tell from the error message because it's trying to open something starting with /c:/... and the leading slash looks wrong there).

The latter case I don't understand just yet. Do you have any request-altering middleware in place? It looks like the request object is not a class instance, but a function instead, which would mean lots of stuff would break if we were doing that all the time (for example, most views). Can you test that this still fails when you have all optional pieces of middleware disabled, for example.

comment:2 by yportne@…, 18 years ago

Summary: Cache does not work on win32Cache does not work

Having the same or similair issue on a linux installation when trying to do 'per-view' cache

From settings.py....

CACHE_BACKEND = 'file:///home/django/cache'
CACHE_MIDDLEWARE_SECONDS = 60*60*24
MIDDLEWARE_CLASSES = (
    'django.middleware.common.CommonMiddleware',
)

and the error I am getting is....

ViewDoesNotExist at /mysite/graph/test/
Tried avail in module mysite.graph.views. Error was: 'function' object has no attribute 'method'

If I comment out the "@cache_page(60*24*24)" line in the view, it loads fine...
I can also use the low-level cache API without any issues
FYI - Using Python 2.4.3 on Ubuntu 6.06

comment:3 by Adrian Holovaty, 18 years ago

Summary: Cache does not workCache does not work for some indeterminate setup

It's working fine for me, on both Linux and Solaris. Please post your full traceback and the full source code of your view function, including the cache_page decorator.

comment:4 by yportne@…, 18 years ago

OK, I made another app with a simple view to rule out any issues there... the simplified view is:

from django.views.decorators.cache import cache_page
from django.http import HttpResponse
import sys

@cache_page(60*60*24)
def cacheindex(request):
  return HttpResponse(sys.version,'text/plain')

and the result I am getting is:

Traceback (most recent call last):
File "/usr/lib/python2.4/site-packages/django/core/handlers/base.py" in get_response
  65. callback, callback_args, callback_kwargs = resolver.resolve(path)
File "/usr/lib/python2.4/site-packages/django/core/urlresolvers.py" in resolve
  158. sub_match = pattern.resolve(new_path)
File "/usr/lib/python2.4/site-packages/django/core/urlresolvers.py" in resolve
  114. return self.callback, args, kwargs
File "/usr/lib/python2.4/site-packages/django/core/urlresolvers.py" in _get_callback
  125. raise ViewDoesNotExist, "Tried %s in module %s. Error was: %s" % (func_name, mod_name, str(e))

  ViewDoesNotExist at /mysite/test/cache/
  Tried cacheindex in module mysite.test.views. Error was: 'function' object has no attribute 'method'

but if I comment out the @cache_page line it runs fine...

2.4.3 (#2, Apr 27 2006, 14:43:58) 
[GCC 4.0.3 (Ubuntu 4.0.3-1ubuntu5)]

FYI - Relatively new to Python and Django, so it could certainly be me, I just posted because it seemed like another case of the original problem, which it now looks like it might not be...

comment:5 by [530], 18 years ago

Keywords: linux freebsd added

Got the same error on freebsd, django trunk revision 3705

comment:6 by [530], 18 years ago

Btw, works with wrapped function, but not as decorator, and yes, it is python 2.4 :)

comment:7 by atlithorn, 18 years ago

I have the same problem, running python2.4 on windows XP and this decorator does not work with the 2.4 syntax but fine with the wrapper method. Plenty of other django decorators work though.

comment:8 by atlithorn, 18 years ago

The python2.4 syntax actually works if I don't add the (seconds) parameter. Tried this
@cache_page(cache_timeout=60*60*24)
def bla(request):
....

But then I got
_decorator_from_middleware() takes at least 1 non-keyword argument (0 given)

comment:9 by pb@…, 17 years ago

Cc: ca.dein@… added

I'm seeing this too. Trunk r3817, Python 2.4.3, FreeBSD 6.1. cache_page works as wrapper function, not as decorator. Sorry I don't have more time right now to look into why that might be...

comment:10 by Simon G. <dev@…>, 17 years ago

Triage Stage: UnreviewedAccepted

comment:11 by Simon G. <dev@…>, 17 years ago

Summary: Cache does not work for some indeterminate setupcache_page works as wrapper function, not as decorator

comment:12 by anonymous, 17 years ago

Looks like it is a duplicate to ticket:1015.

comment:13 by Gary Wilson <gary.wilson@…>, 17 years ago

Resolution: duplicate
Status: newclosed

duplicate of #1015.

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