From aee0f95b371d42727121790a57009a408f1c5606 Mon Sep 17 00:00:00 2001 From: James Gutu Date: Fri, 3 Oct 2025 22:26:21 +0300 Subject: [PATCH 1/5] fix for django unicode decode error --- debug_toolbar/panels/settings.py | 10 +++++++++- tests/panels/test_settings.py | 2 +- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/debug_toolbar/panels/settings.py b/debug_toolbar/panels/settings.py index 68ab44c0b..cf8b4fe79 100644 --- a/debug_toolbar/panels/settings.py +++ b/debug_toolbar/panels/settings.py @@ -1,6 +1,7 @@ from django.utils.encoding import force_str from django.utils.translation import gettext_lazy as _ from django.views.debug import get_default_exception_reporter_filter +from django.utils.encoding import DjangoUnicodeDecodeError from debug_toolbar.panels import Panel @@ -24,10 +25,17 @@ def title(self): ) def generate_stats(self, request, response): + + def catch_force_errors(force_function, value): + try: + return force_function(value) + except DjangoUnicodeDecodeError: + return 'Debug toolbar was unable to parse value' + self.record_stats( { "settings": { - key: force_str(value) + key: catch_force_errors(force_str, value) for key, value in sorted(get_safe_settings().items()) } } diff --git a/tests/panels/test_settings.py b/tests/panels/test_settings.py index 89b016dc0..3eb40f0e7 100644 --- a/tests/panels/test_settings.py +++ b/tests/panels/test_settings.py @@ -3,7 +3,7 @@ from ..base import IntegrationTestCase -@override_settings(DEBUG=True) +@override_settings(DEBUG=True, RANDOM_SETTING=bytes.fromhex("a3f2b8c14e972d5a8fb3c7291a64e0859c472bf63d18a0945e73b2c84f917ae2")) class SettingsIntegrationTestCase(IntegrationTestCase): def test_panel_title(self): response = self.client.get("/regular/basic/") From b9e99226026e45abbe8c3ab0bcde90f4ffeabe14 Mon Sep 17 00:00:00 2001 From: James Gutu Date: Fri, 3 Oct 2025 22:40:49 +0300 Subject: [PATCH 2/5] fix for django unicode decode error --- docs/changes.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/changes.rst b/docs/changes.rst index 452242279..8552bc3d6 100644 --- a/docs/changes.rst +++ b/docs/changes.rst @@ -13,6 +13,8 @@ Pending class instance, regardless if any data was generated. * Fixed selenium tests for CI by using psycopg for Python 3.13 runs. * Added ``CommunityPanel`` containing links to documentation and resources. +* Fixed force_str to catch error and give out degault string if value is not + serializable 6.0.0 (2025-07-22) ------------------ From 57541b76806f0cd17f55ca72a674575637d4af67 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 3 Oct 2025 19:42:41 +0000 Subject: [PATCH 3/5] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- debug_toolbar/panels/settings.py | 6 ++---- tests/panels/test_settings.py | 7 ++++++- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/debug_toolbar/panels/settings.py b/debug_toolbar/panels/settings.py index cf8b4fe79..e985e7790 100644 --- a/debug_toolbar/panels/settings.py +++ b/debug_toolbar/panels/settings.py @@ -1,7 +1,6 @@ -from django.utils.encoding import force_str +from django.utils.encoding import DjangoUnicodeDecodeError, force_str from django.utils.translation import gettext_lazy as _ from django.views.debug import get_default_exception_reporter_filter -from django.utils.encoding import DjangoUnicodeDecodeError from debug_toolbar.panels import Panel @@ -25,12 +24,11 @@ def title(self): ) def generate_stats(self, request, response): - def catch_force_errors(force_function, value): try: return force_function(value) except DjangoUnicodeDecodeError: - return 'Debug toolbar was unable to parse value' + return "Debug toolbar was unable to parse value" self.record_stats( { diff --git a/tests/panels/test_settings.py b/tests/panels/test_settings.py index 3eb40f0e7..5ea5345a9 100644 --- a/tests/panels/test_settings.py +++ b/tests/panels/test_settings.py @@ -3,7 +3,12 @@ from ..base import IntegrationTestCase -@override_settings(DEBUG=True, RANDOM_SETTING=bytes.fromhex("a3f2b8c14e972d5a8fb3c7291a64e0859c472bf63d18a0945e73b2c84f917ae2")) +@override_settings( + DEBUG=True, + RANDOM_SETTING=bytes.fromhex( + "a3f2b8c14e972d5a8fb3c7291a64e0859c472bf63d18a0945e73b2c84f917ae2" + ), +) class SettingsIntegrationTestCase(IntegrationTestCase): def test_panel_title(self): response = self.client.get("/regular/basic/") From f35646a4588b46d677422d99af03fdd8d4e4ade5 Mon Sep 17 00:00:00 2001 From: James Gutu Date: Fri, 3 Oct 2025 22:54:33 +0300 Subject: [PATCH 4/5] fixed linting problem --- tests/panels/test_settings.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tests/panels/test_settings.py b/tests/panels/test_settings.py index 3eb40f0e7..5ea5345a9 100644 --- a/tests/panels/test_settings.py +++ b/tests/panels/test_settings.py @@ -3,7 +3,12 @@ from ..base import IntegrationTestCase -@override_settings(DEBUG=True, RANDOM_SETTING=bytes.fromhex("a3f2b8c14e972d5a8fb3c7291a64e0859c472bf63d18a0945e73b2c84f917ae2")) +@override_settings( + DEBUG=True, + RANDOM_SETTING=bytes.fromhex( + "a3f2b8c14e972d5a8fb3c7291a64e0859c472bf63d18a0945e73b2c84f917ae2" + ), +) class SettingsIntegrationTestCase(IntegrationTestCase): def test_panel_title(self): response = self.client.get("/regular/basic/") From 8fd6bbe3f793017db8d4a228cec89a10acdd9d67 Mon Sep 17 00:00:00 2001 From: James Gutu Date: Fri, 3 Oct 2025 23:39:23 +0300 Subject: [PATCH 5/5] corrected spelling mistake --- docs/changes.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/changes.rst b/docs/changes.rst index 8552bc3d6..ae4b89f21 100644 --- a/docs/changes.rst +++ b/docs/changes.rst @@ -13,8 +13,8 @@ Pending class instance, regardless if any data was generated. * Fixed selenium tests for CI by using psycopg for Python 3.13 runs. * Added ``CommunityPanel`` containing links to documentation and resources. -* Fixed force_str to catch error and give out degault string if value is not - serializable +* Fixed force_str to catch error and give out default string if value is not + serializable. 6.0.0 (2025-07-22) ------------------