jazzband / django-debug-toolbar

A configurable set of panels that display various debug information about the current request/response.
https://django-debug-toolbar.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
7.97k stars 1.03k forks source link

Exception while resolving variable 'toolbar' in template #1905

Closed foundkey closed 2 months ago

foundkey commented 2 months ago

When sending a request using ajax, toolbar.js will send a request at the same time: GET /__debug__/history_sidebar/?store_id=<id> HTTP/1.1

This request will throw the following exception when rendering the template:

Traceback (most recent call last): File "/Users/.venv/lib/python3.10/site-packages/django/template/base.py", line 898, in _resolve_lookup raise VariableDoesNotExist( django.template.base.VariableDoesNotExist: Failed lookup for key [toolbar] in [{'True': True, 'False': False, 'None': None}, {'panel': <debug_toolbar.panels.cache.CachePanel object at 0x11f936590>}] [DEBUG] 12/Apr/2024 10:31:22 - Exception while resolving variable 'toolbar' in template 'debug_toolbar/includes/panel_content.html'. Traceback (most recent call last): File "/Users/.venv/lib/python3.10/site-packages/django/template/base.py", line 875, in _resolve_lookup current = current[bit] File "/Users/.venv/lib/python3.10/site-packages/django/template/context.py", line 83, in getitem raise KeyError(key) KeyError: 'toolbar'

This request is handled by this method: history_sidebar(request) It seems because toolbar is not passed in panel_context.

foundkey commented 2 months ago

After turning on Debug level logging, VariableDoesNotExist errors appear frequently during use. But it does not affect the use.

tim-schilling commented 2 months ago

Hmm. I'm softening on my earlier stance on the PR.