summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
authorMariusz Felisiak <felisiak.mariusz@gmail.com>2021-12-16 20:13:17 +0100
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2021-12-16 20:14:17 +0100
commitc1d2e8b9b8f41d3effef03badc78c8b8995a99b6 (patch)
tree7e51116b27998d63218153f3e0ea36586964d27b /django
parent267a743bf253a4e0703c0257a5df7774116c3194 (diff)
[4.0.x] Fixed #33350 -- Reallowed using cache decorators with duck-typed HttpRequest.
Regression in 3fd82a62415e748002435e7bad06b5017507777c. Thanks Terence Honles for the report. Backport of 40165eecc40f9e223702a41a0cb0958515bb1f82 from main
Diffstat (limited to 'django')
-rw-r--r--django/views/decorators/cache.py7
1 files changed, 4 insertions, 3 deletions
diff --git a/django/views/decorators/cache.py b/django/views/decorators/cache.py
index fdc5917738..417f3614f8 100644
--- a/django/views/decorators/cache.py
+++ b/django/views/decorators/cache.py
@@ -1,6 +1,5 @@
from functools import wraps
-from django.http import HttpRequest
from django.middleware.cache import CacheMiddleware
from django.utils.cache import add_never_cache_headers, patch_cache_control
from django.utils.decorators import decorator_from_middleware_with_args
@@ -29,7 +28,8 @@ def cache_control(**kwargs):
def _cache_controller(viewfunc):
@wraps(viewfunc)
def _cache_controlled(request, *args, **kw):
- if not isinstance(request, HttpRequest):
+ # Ensure argument looks like a request.
+ if not hasattr(request, 'META'):
raise TypeError(
"cache_control didn't receive an HttpRequest. If you are "
"decorating a classmethod, be sure to use "
@@ -48,7 +48,8 @@ def never_cache(view_func):
"""
@wraps(view_func)
def _wrapped_view_func(request, *args, **kwargs):
- if not isinstance(request, HttpRequest):
+ # Ensure argument looks like a request.
+ if not hasattr(request, 'META'):
raise TypeError(
"never_cache didn't receive an HttpRequest. If you are "
"decorating a classmethod, be sure to use @method_decorator."