Skip to content

Commit 27598e7

Browse files
authored
Avoid a too broad try...except NameError clause (#1443)
Refs #1437
1 parent 805acf4 commit 27598e7

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

debug_toolbar/panels/cache.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66
try:
77
from django.utils.connection import ConnectionProxy
88
except ImportError:
9-
# Django 3.1 and below doesn't have a ConnectionProxy
10-
pass
9+
ConnectionProxy = None
1110

1211
from django.conf import settings
1312
from django.core import cache
@@ -257,10 +256,9 @@ def enable_instrumentation(self):
257256
else:
258257
cache.caches = CacheHandlerPatch()
259258

260-
try:
259+
# Wrap the patched cache inside Django's ConnectionProxy
260+
if ConnectionProxy:
261261
cache.cache = ConnectionProxy(cache.caches, DEFAULT_CACHE_ALIAS)
262-
except NameError:
263-
pass
264262

265263
def disable_instrumentation(self):
266264
cache.caches = original_caches

0 commit comments

Comments
 (0)