Code

Opened 5 years ago

Closed 4 years ago

Last modified 4 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: UI/UX:

Description (last modified by Alex)

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 4 years ago.
Patch for cache decorator function
cache_page_default_timeout.diff (1.8 KB) - added by j4mie 4 years ago.
Slightly different approach at patch, includes test

Download all attachments as: .zip

Change History (10)

comment:1 Changed 5 years ago by Alex

  • Description modified (diff)
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

Please use preview.

comment:2 Changed 4 years ago by russellm

  • Triage Stage changed from Unreviewed to Accepted

comment:3 follow-up: Changed 4 years ago by rokclimb15

  • Has patch set
  • Keywords @cache_page added
  • Summary changed from @cache_page with no args causes AttributeError with wsgi to @cache_page with no args causes IndexError
  • Version changed from 1.1 to SVN

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 4 years ago by rokclimb15

Patch for cache decorator function

comment:4 in reply to: ↑ 3 Changed 4 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 4 years ago by lukeplant

  • Needs tests set

With tests this will probably be good to go.

Changed 4 years ago by j4mie

Slightly different approach at patch, includes test

comment:6 Changed 4 years ago by j4mie

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 4 years ago by lukeplant

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

(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 4 years ago by lukeplant

(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

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.