From c8e22a64de7da38dd0bb304917bc0911ca6b082d Mon Sep 17 00:00:00 2001 From: Matthias Kestenholz Date: Wed, 21 Aug 2024 16:03:34 +0200 Subject: [PATCH 1/2] Refs #1668: Fixed the unsortable session keys fallback --- debug_toolbar/panels/request.py | 5 ++++- docs/changes.rst | 2 ++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/debug_toolbar/panels/request.py b/debug_toolbar/panels/request.py index 9e60207fe..614c34f8a 100644 --- a/debug_toolbar/panels/request.py +++ b/debug_toolbar/panels/request.py @@ -64,5 +64,8 @@ def generate_stats(self, request, response): (k, request.session.get(k)) for k in sorted(request.session.keys()) ] except TypeError: - session_list = [(k, request.session.get(k)) for k in request.session] + session_list = [ + (k, request.session.get(k)) + for k in request.session.keys() # noqa: SIM118 (it's not a dict) + ] self.record_stats({"session": {"list": session_list}}) diff --git a/docs/changes.rst b/docs/changes.rst index 8de32a1d2..581a9fce1 100644 --- a/docs/changes.rst +++ b/docs/changes.rst @@ -13,6 +13,8 @@ Pending * Add translations for Bulgarian and Korean. * Update translations for several languages. * Include new translatable strings for translation. +* Fixed a crash which happened in the fallback case when session keys cannot be + sorted. 4.4.6 (2024-07-10) ------------------ From 53947042eb988c7a325a798032919fa07d4741a9 Mon Sep 17 00:00:00 2001 From: Matthias Kestenholz Date: Wed, 21 Aug 2024 16:10:56 +0200 Subject: [PATCH 2/2] Disable the flake8-simplify ruleset --- debug_toolbar/panels/request.py | 2 +- pyproject.toml | 8 +++----- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/debug_toolbar/panels/request.py b/debug_toolbar/panels/request.py index 614c34f8a..b77788637 100644 --- a/debug_toolbar/panels/request.py +++ b/debug_toolbar/panels/request.py @@ -66,6 +66,6 @@ def generate_stats(self, request, response): except TypeError: session_list = [ (k, request.session.get(k)) - for k in request.session.keys() # noqa: SIM118 (it's not a dict) + for k in request.session.keys() # (it's not a dict) ] self.record_stats({"session": {"list": session_list}}) diff --git a/pyproject.toml b/pyproject.toml index 6060a055f..451887d35 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -74,16 +74,14 @@ lint.extend-select = [ "PGH", # pygrep-hooks "PIE", # flake8-pie "RUF100", # Unused noqa directive - "SIM", # flake8-simplify "SLOT", # flake8-slots "UP", # pyupgrade "W", # pycodestyle warnings ] lint.extend-ignore = [ - "B905", # Allow zip() without strict= - "E501", # Ignore line length violations - "SIM108", # Use ternary operator instead of if-else-block - "UP031", # It's not always wrong to use percent-formatting + "B905", # Allow zip() without strict= + "E501", # Ignore line length violations + "UP031", # It's not always wrong to use percent-formatting ] lint.per-file-ignores."*/migrat*/*" = [ "N806", # Allow using PascalCase model names in migrations