From 10e1d004c735c1e547d084733b8af74480b17264 Mon Sep 17 00:00:00 2001 From: Matthias Kestenholz Date: Sat, 23 Jan 2021 21:09:12 +0100 Subject: [PATCH] Avoid a too broad try...except NameError clause Refs #1437 --- debug_toolbar/panels/cache.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/debug_toolbar/panels/cache.py b/debug_toolbar/panels/cache.py index e7f3f467e..b4c486124 100644 --- a/debug_toolbar/panels/cache.py +++ b/debug_toolbar/panels/cache.py @@ -6,8 +6,7 @@ try: from django.utils.connection import ConnectionProxy except ImportError: - # Django 3.1 and below doesn't have a ConnectionProxy - pass + ConnectionProxy = None from django.conf import settings from django.core import cache @@ -257,10 +256,9 @@ def enable_instrumentation(self): else: cache.caches = CacheHandlerPatch() - try: + # Wrap the patched cache inside Django's ConnectionProxy + if ConnectionProxy: cache.cache = ConnectionProxy(cache.caches, DEFAULT_CACHE_ALIAS) - except NameError: - pass def disable_instrumentation(self): cache.caches = original_caches