Opened 15 years ago

Closed 14 years ago

Last modified 14 years ago

#12019 closed (fixed)

@cache_page with no args causes IndexError

Reported by: rokclimb15 Owned by: nobody
Component: Core (Cache system) Version: dev
Severity: Keywords: @cache_page
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: yes Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Alex Gaynor)

When calling @cache_page with no arguments I get the following exception while running mod_wsgi. I'm not sure if that usage is valid. I would assume it would use CACHE_MIDDLEWARE_SECONDS if nothing is provided, but I can't find anything about that in docs or see any evidence of that in the code. If that argument is required, I think a clear exception should be thrown rather than this one when running under mod_wsgi.

Traceback (most recent call last):

 File "/usr/lib/python2.6/dist-packages/django/core/handlers/base.py", line 92, in get_response
   response = callback(request, *callback_args, **callback_kwargs)

 File "/usr/lib/python2.6/dist-packages/django/utils/decorators.py", line 33, in adapt
   return MethodDecoratorAdaptor(decorator, func)

 File "/usr/lib/python2.6/dist-packages/django/utils/decorators.py", line 15, in __init__
   update_wrapper(self, func)

 File "/usr/lib/python2.6/functools.py", line 33, in update_wrapper
   setattr(wrapper, attr, getattr(wrapped, attr))

AttributeError: 'WSGIRequest' object has no attribute '__name__'

Attachments (2)

cache.py.patch (1.2 KB ) - added by rokclimb15 15 years ago.
Patch for cache decorator function
cache_page_default_timeout.diff (1.8 KB ) - added by Jamie Matthews 14 years ago.
Slightly different approach at patch, includes test

Download all attachments as: .zip

Change History (10)

comment:1 by Alex Gaynor, 15 years ago

Description: modified (diff)

Please use preview.

comment:2 by Russell Keith-Magee, 15 years ago

Triage Stage: UnreviewedAccepted

comment:3 by rokclimb15, 15 years ago

Has patch: set
Keywords: @cache_page added
Summary: @cache_page with no args causes AttributeError with wsgi@cache_page with no args causes IndexError
Version: 1.1SVN

This behavior with mod_wsgi actually translates to an IndexError in the cache decorator code. The docs at http://docs.djangoproject.com/en/dev/ref/settings/#cache-middleware-seconds state that this setting will be used as a default for the cache middleware and decorators, which is not currently true. The attached patch adds this functionality to match the documentation, which is also a sensible behavior in my opinion. The patch isn't particularly pretty, but neither is this decorator's code since it is littered with backwards compat functionality.

by rokclimb15, 15 years ago

Attachment: cache.py.patch added

Patch for cache decorator function

in reply to:  3 comment:4 by pat_riot666, 15 years ago

Replying to rokclimb15:

This behavior with mod_wsgi actually translates to an IndexError in the cache decorator code. The docs at http://docs.djangoproject.com/en/dev/ref/settings/#cache-middleware-seconds state that this setting will be used as a default for the cache middleware and decorators, which is not currently true. The attached patch adds this functionality to match the documentation, which is also a sensible behavior in my opinion. The patch isn't particularly pretty, but neither is this decorator's code since it is littered with backwards compat functionality.

This patch seems to work fine for me as well. Any chance of this getting fixed?

comment:5 by Luke Plant, 14 years ago

Needs tests: set

With tests this will probably be good to go.

by Jamie Matthews, 14 years ago

Slightly different approach at patch, includes test

comment:6 by Jamie Matthews, 14 years ago

Added a slightly different approach at the patch, which allows the middleware to deal with the default cache timeout value. Hopefully a little more DRY. Also added a test.

comment:7 by Luke Plant, 14 years ago

Resolution: fixed
Status: newclosed

(In [13864]) Fixed #12019 - backwards compatibility issues with cache_page decorator.

Thanks to rokclimb15 for the report, and j4mie/rokclimb15 for the patches.

comment:8 by Luke Plant, 14 years ago

(In [13865]) [1.2.X] Fixed #12019 - backwards compatibility issues with cache_page decorator.

Thanks to rokclimb15 for the report, and j4mie/rokclimb15 for the patches.

Backport of [13864] from trunk

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