File tree Expand file tree Collapse file tree 3 files changed +25
-1
lines changed
Expand file tree Collapse file tree 3 files changed +25
-1
lines changed Original file line number Diff line number Diff line change @@ -45,9 +45,13 @@ def wrapper(*args, **kwargs):
4545
4646
4747def _monkey_patch_cache (cache , alias , panel ):
48- if not getattr (cache , "_djdt_panel" , None ):
48+ if not hasattr (cache , "_djdt_panel" ):
49+ # The panel has never been monkey patched before
4950 for name in WRAPPED_CACHE_METHODS :
5051 _monkey_patch_method (cache , name , alias )
52+ if not getattr (cache , "_djdt_panel" , None ):
53+ # This is used for both initially monkey patching and re-enabling the
54+ # instrumentation.
5155 cache ._djdt_panel = panel
5256
5357
Original file line number Diff line number Diff line change @@ -16,6 +16,8 @@ Pending
1616 rather than on instantiation.
1717* Highlighted the documentation about disabling the browser's caching to
1818 ensure the latest static assets are used.
19+ * Fixed bug with ``CachePanel `` so the cache patching is only applied
20+ once.
1921
20226.2.0 (2026-01-20)
2123------------------
Original file line number Diff line number Diff line change @@ -158,3 +158,21 @@ def test_generate_server_timing(self):
158158 def test_backend_alias_is_recorded (self ):
159159 cache .cache .get ("foo" )
160160 self .assertEqual (self .panel .calls [0 ]["backend" ], "default (LocMemCache)" )
161+
162+ def test_patching_only_applied_once (self ):
163+ """
164+ Confirm that reapplying and disabling the cache patching only wraps
165+ the cache methods once
166+ """
167+ for _ in range (2 ):
168+ self .panel .enable_instrumentation ()
169+ self .panel .disable_instrumentation ()
170+ nested_wraps = 0
171+ wrapped = cache .cache .get .__wrapped__
172+ while wrapped is not None :
173+ try :
174+ wrapped = wrapped .__wrapped__
175+ nested_wraps += 1
176+ except AttributeError :
177+ break
178+ self .assertEqual (nested_wraps , 0 )
You can’t perform that action at this time.
0 commit comments