Skip to content

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

Closed
@danjac

Description

@danjac

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'
``

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions