Skip to content

Commit 805acf4

Browse files
authored
Merge pull request #1437 from gilmrjc/fix-test-django-3-2
Patch default cache when using the cache panel
2 parents f4d1605 + 6b524a6 commit 805acf4

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

debug_toolbar/panels/cache.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,20 @@
33
import time
44
from collections import OrderedDict
55

6+
try:
7+
from django.utils.connection import ConnectionProxy
8+
except ImportError:
9+
# Django 3.1 and below doesn't have a ConnectionProxy
10+
pass
11+
612
from django.conf import settings
713
from django.core import cache
8-
from django.core.cache import CacheHandler, caches as original_caches
14+
from django.core.cache import (
15+
DEFAULT_CACHE_ALIAS,
16+
CacheHandler,
17+
cache as original_cache,
18+
caches as original_caches,
19+
)
920
from django.core.cache.backends.base import BaseCache
1021
from django.dispatch import Signal
1122
from django.middleware import cache as middleware_cache
@@ -246,8 +257,14 @@ def enable_instrumentation(self):
246257
else:
247258
cache.caches = CacheHandlerPatch()
248259

260+
try:
261+
cache.cache = ConnectionProxy(cache.caches, DEFAULT_CACHE_ALIAS)
262+
except NameError:
263+
pass
264+
249265
def disable_instrumentation(self):
250266
cache.caches = original_caches
267+
cache.cache = original_cache
251268
# While it can be restored to the original, any views that were
252269
# wrapped with the cache_page decorator will continue to use a
253270
# monkey patched cache.

0 commit comments

Comments
 (0)