django-commons / 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
8.08k stars 1.05k forks source link

KeyError: "alerts" in nav_subtitle if alerts stats not present #1951

Closed danjac closed 3 months ago

danjac commented 3 months ago

If the stats for the alert panel are absent (e.g. a StreamingHttpResponse) a KeyError is raised:


  File "/my-project/.venv/lib/python3.12/site-packages/django/template/base.py", line 710, in resolve
    obj = self.var.resolve(context)
          ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/my-project/.venv/lib/python3.12/site-packages/django/template/base.py", line 842, in resolve
    value = self._resolve_lookup(context)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/my-project/.venv/lib/python3.12/site-packages/django/template/base.py", line 885, in _resolve_lookup
    current = getattr(current, bit)
              ^^^^^^^^^^^^^^^^^^^^^
  File "/my-project/.venv/lib/python3.12/site-packages/debug_toolbar/panels/alerts.py", line 86, in nav_subtitle
    alerts = self.get_stats()["alerts"]
             ^^^^^^^^^^^^^^^^^^^^^^^^^^
KeyError: 'alerts'
``
matthiask commented 3 months ago

Thanks for the report! #1953 hopefully fixes this.

danjac commented 3 months ago

Really fast turnaround, thank you!