Opened 9 years ago

Closed 8 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: master
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: UI/UX:

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 Changed 9 years ago by mtredinnick

  • priority changed from highest to normal
  • Severity changed from blocker to normal

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 Changed 9 years ago by yportne@…

  • Summary changed from Cache does not work on win32 to Cache 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 Changed 9 years ago by adrian

  • Summary changed from Cache does not work to Cache 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 Changed 9 years ago by yportne@…

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 Changed 9 years ago by [530]

  • Keywords linux freebsd added

Got the same error on freebsd, django trunk revision 3705

comment:6 Changed 9 years ago by [530]

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

comment:7 Changed 9 years ago by atlithorn

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 Changed 9 years ago by atlithorn

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 Changed 9 years ago by pb@…

  • 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 Changed 8 years ago by Simon G. <dev@…>

  • Triage Stage changed from Unreviewed to Accepted

comment:11 Changed 8 years ago by Simon G. <dev@…>

  • Summary changed from Cache does not work for some indeterminate setup to cache_page works as wrapper function, not as decorator

comment:12 Changed 8 years ago by anonymous

Looks like it is a duplicate to ticket:1015.

comment:13 Changed 8 years ago by Gary Wilson <gary.wilson@…>

  • Resolution set to duplicate
  • Status changed from new to closed

duplicate of #1015.

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