Skip to content

Commit 15b427a

Browse files
authored
Merge pull request #1415 from jazzband/mk/1403
History panel: Do not crash when receiving invalid JSON
2 parents 1181f2d + cf01994 commit 15b427a

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

debug_toolbar/panels/history/panel.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,10 @@ def generate_stats(self, request, response):
4949
and request.body
5050
and request.META.get("CONTENT_TYPE") == "application/json"
5151
):
52-
data = json.loads(request.body)
52+
try:
53+
data = json.loads(request.body)
54+
except ValueError:
55+
pass
5356
except RawPostDataException:
5457
# It is not guaranteed that we may read the request data (again).
5558
data = None

docs/changes.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ unreleased
55
----------
66

77
* Moved CI to GitHub Actions: https://github.com/jazzband/django-debug-toolbar/actions
8+
* Stopped crashing when ``request.GET`` and ``request.POST`` are
9+
dictionaries instead of ``QueryDict`` instances. This isn't a valid
10+
use of Django but django-debug-toolbar shouldn't crash anyway.
11+
* Fixed a crash in the history panel when sending a JSON POST request
12+
with invalid JSON.
13+
814

915
3.2a1 (2020-10-19)
1016
------------------

tests/panels/test_history.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ def test_post(self):
3030
def test_post_json(self):
3131
for data, expected_stats_data in (
3232
({"foo": "bar"}, {"foo": "bar"}),
33-
("", {}),
33+
("", {}), # Empty JSON
34+
("'", {}), # Invalid JSON
3435
):
3536
with self.subTest(data=data):
3637
self.request = rf.post(

0 commit comments

Comments
 (0)