Opened 11 years ago

Closed 10 years ago

Last modified 10 years ago

#12019 closed (fixed)

@cache_page with no args causes IndexError

Reported by: rokclimb15 Owned by: nobody
Component: Core (Cache system) Version: master
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 10 years ago.
Patch for cache decorator function
cache_page_default_timeout.diff (1.8 KB) - added by Jamie Matthews 10 years ago.
Slightly different approach at patch, includes test

Download all attachments as: .zip

Change History (10)

comment:1 Changed 11 years ago by Alex Gaynor

Description: modified (diff)

Please use preview.

comment:2 Changed 10 years ago by Russell Keith-Magee

Triage Stage: UnreviewedAccepted

comment:3 Changed 10 years ago by rokclimb15

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.

Changed 10 years ago by rokclimb15

Attachment: cache.py.patch added

Patch for cache decorator function

comment:4 in reply to:  3 Changed 10 years ago by pat_riot666

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 Changed 10 years ago by Luke Plant

Needs tests: set

With tests this will probably be good to go.

Changed 10 years ago by Jamie Matthews

Slightly different approach at patch, includes test

comment:6 Changed 10 years ago by Jamie Matthews

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 Changed 10 years ago by Luke Plant

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 Changed 10 years ago by Luke Plant

(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