Skip to content

Request with invalid json content type fails with a JSONDecodeError when using the history panel #1403

Closed
@israel-tk

Description

@israel-tk

Similar to #1330

If an API request is made with invalid json and the content type application/json, the history panel raises an error and the whole API request fails. django-debug-toolbar 3.1.1.

>>> Client(enforce_csrf_checks=True).post(
            "some-valid-url", data="invalid-json", content_type="application/json",
        )
/usr/local/lib/python3.8/site-packages/django/test/client.py:742: in post
    response = super().post(path, data=data, content_type=content_type, secure=secure, **extra)
/usr/local/lib/python3.8/site-packages/django/test/client.py:404: in post
    return self.generic('POST', path, post_data, content_type,
/usr/local/lib/python3.8/site-packages/django/test/client.py:470: in generic
    return self.request(**r)
/usr/local/lib/python3.8/site-packages/django/test/client.py:710: in request
    self.check_exception(response)
/usr/local/lib/python3.8/site-packages/django/test/client.py:571: in check_exception
    raise exc_value
/usr/local/lib/python3.8/site-packages/django/core/handlers/exception.py:47: in inner
    response = get_response(request)
/usr/local/lib/python3.8/site-packages/debug_toolbar/middleware.py:67: in __call__
    panel.generate_stats(request, response)
/usr/local/lib/python3.8/site-packages/debug_toolbar/panels/history/panel.py:57: in generate_stats
    data = json.loads(
/usr/local/lib/python3.8/json/__init__.py:357: in loads
    return _default_decoder.decode(s)
/usr/local/lib/python3.8/json/decoder.py:337: in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())

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