From dfad5dbef571eebca89e02b7a676ec326428931b Mon Sep 17 00:00:00 2001 From: Matthias Kestenholz Date: Fri, 5 Jul 2024 16:59:55 +0200 Subject: [PATCH 1/5] Close #1509: Revert the infinite recursion fix, Django has changed the behavior (#1955) --- tests/forms.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/forms.py b/tests/forms.py index 9a4d38769..916cb6612 100644 --- a/tests/forms.py +++ b/tests/forms.py @@ -6,4 +6,4 @@ class TemplateReprForm(forms.Form): user = forms.ModelChoiceField(queryset=User.objects.all()) def __repr__(self): - return repr(self) + return str(self) From 699c1d96d0899342e7aaa2fa5129802f44096966 Mon Sep 17 00:00:00 2001 From: "Bart K. de Koning" <118313986+bkdekoning@users.noreply.github.com> Date: Sat, 6 Jul 2024 02:26:37 -0400 Subject: [PATCH 2/5] Fixed order and grammatical number of panels in documentation (#1956) * fixed order and grammatical number of panels in documentation * updated changes.rst to reflect change to docs --- docs/changes.rst | 3 +++ docs/panels.rst | 42 +++++++++++++++++++++--------------------- 2 files changed, 24 insertions(+), 21 deletions(-) diff --git a/docs/changes.rst b/docs/changes.rst index 952e6e996..d47f69784 100644 --- a/docs/changes.rst +++ b/docs/changes.rst @@ -4,6 +4,9 @@ Change log Pending ------- +* Changed ordering (and grammatical number) of panels and their titles in + documentation to match actual panel ordering and titles. + 4.4.5 (2024-07-05) ------------------ diff --git a/docs/panels.rst b/docs/panels.rst index c9ea6bbf0..7892dcf94 100644 --- a/docs/panels.rst +++ b/docs/panels.rst @@ -9,17 +9,6 @@ Default built-in panels The following panels are enabled by default. -Alerts -~~~~~~~ - -.. class:: debug_toolbar.panels.alerts.AlertsPanel - -This panel shows alerts for a set of pre-defined cases: - -- Alerts when the response has a form without the - ``enctype="multipart/form-data"`` attribute and the form contains - a file input. - History ~~~~~~~ @@ -33,8 +22,8 @@ snapshot of the toolbar to view that request's stats. ``True`` or if the server runs with multiple processes, the History Panel will be disabled. -Version -~~~~~~~ +Versions +~~~~~~~~ .. class:: debug_toolbar.panels.versions.VersionsPanel @@ -80,19 +69,30 @@ SQL SQL queries including time to execute and links to EXPLAIN each query. -Template -~~~~~~~~ +Static files +~~~~~~~~~~~~ + +.. class:: debug_toolbar.panels.staticfiles.StaticFilesPanel + +Used static files and their locations (via the ``staticfiles`` finders). + +Templates +~~~~~~~~~ .. class:: debug_toolbar.panels.templates.TemplatesPanel Templates and context used, and their template paths. -Static files -~~~~~~~~~~~~ +Alerts +~~~~~~~ -.. class:: debug_toolbar.panels.staticfiles.StaticFilesPanel +.. class:: debug_toolbar.panels.alerts.AlertsPanel -Used static files and their locations (via the ``staticfiles`` finders). +This panel shows alerts for a set of pre-defined cases: + +- Alerts when the response has a form without the + ``enctype="multipart/form-data"`` attribute and the form contains + a file input. Cache ~~~~~ @@ -101,8 +101,8 @@ Cache Cache queries. Is incompatible with Django's per-site caching. -Signal -~~~~~~ +Signals +~~~~~~~ .. class:: debug_toolbar.panels.signals.SignalsPanel From 9bcd6cac17fd1721d60c2b1b8218884caf0ee45e Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 8 Jul 2024 17:33:03 +0000 Subject: [PATCH 3/5] [pre-commit.ci] pre-commit autoupdate MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit updates: - [github.com/astral-sh/ruff-pre-commit: v0.5.0 → v0.5.1](https://github.com/astral-sh/ruff-pre-commit/compare/v0.5.0...v0.5.1) - [github.com/tox-dev/pyproject-fmt: 2.1.3 → 2.1.4](https://github.com/tox-dev/pyproject-fmt/compare/2.1.3...2.1.4) --- .pre-commit-config.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 54a49e4d6..291fc94e9 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -44,13 +44,13 @@ repos: args: - --fix - repo: https://github.com/astral-sh/ruff-pre-commit - rev: 'v0.5.0' + rev: 'v0.5.1' hooks: - id: ruff args: [--fix, --exit-non-zero-on-fix] - id: ruff-format - repo: https://github.com/tox-dev/pyproject-fmt - rev: 2.1.3 + rev: 2.1.4 hooks: - id: pyproject-fmt - repo: https://github.com/abravalheri/validate-pyproject From 982a1271c452ae382c5a851a5484ed3056ef47be Mon Sep 17 00:00:00 2001 From: Matthias Kestenholz Date: Tue, 9 Jul 2024 15:58:52 +0200 Subject: [PATCH 4/5] Alerts panel: Only process HTML responses Closes #1959 --- debug_toolbar/middleware.py | 12 ++---------- debug_toolbar/panels/alerts.py | 4 ++-- debug_toolbar/utils.py | 13 +++++++++++++ docs/changes.rst | 1 + 4 files changed, 18 insertions(+), 12 deletions(-) diff --git a/debug_toolbar/middleware.py b/debug_toolbar/middleware.py index 65b5282c5..b089d1484 100644 --- a/debug_toolbar/middleware.py +++ b/debug_toolbar/middleware.py @@ -11,9 +11,7 @@ from debug_toolbar import settings as dt_settings from debug_toolbar.toolbar import DebugToolbar -from debug_toolbar.utils import clear_stack_trace_caches - -_HTML_TYPES = ("text/html", "application/xhtml+xml") +from debug_toolbar.utils import clear_stack_trace_caches, is_processable_html_response def show_toolbar(request): @@ -102,13 +100,7 @@ def __call__(self, request): response.headers[header] = value # Check for responses where the toolbar can't be inserted. - content_encoding = response.get("Content-Encoding", "") - content_type = response.get("Content-Type", "").split(";")[0] - if ( - getattr(response, "streaming", False) - or content_encoding != "" - or content_type not in _HTML_TYPES - ): + if not is_processable_html_response(response): return response # Insert the toolbar in the response. diff --git a/debug_toolbar/panels/alerts.py b/debug_toolbar/panels/alerts.py index e640dcdd5..51334820d 100644 --- a/debug_toolbar/panels/alerts.py +++ b/debug_toolbar/panels/alerts.py @@ -3,6 +3,7 @@ from django.utils.translation import gettext_lazy as _ from debug_toolbar.panels import Panel +from debug_toolbar.utils import is_processable_html_response class FormParser(HTMLParser): @@ -138,8 +139,7 @@ def check_invalid_file_form_configuration(self, html_content): return self.alerts def generate_stats(self, request, response): - # check if streaming response - if getattr(response, "streaming", True): + if not is_processable_html_response(response): return html_content = response.content.decode(response.charset) diff --git a/debug_toolbar/utils.py b/debug_toolbar/utils.py index 3a9d0882e..1e75cced2 100644 --- a/debug_toolbar/utils.py +++ b/debug_toolbar/utils.py @@ -353,3 +353,16 @@ def get_stack_trace(*, skip=0): def clear_stack_trace_caches(): if hasattr(_local_data, "stack_trace_recorder"): del _local_data.stack_trace_recorder + + +_HTML_TYPES = ("text/html", "application/xhtml+xml") + + +def is_processable_html_response(response): + content_encoding = response.get("Content-Encoding", "") + content_type = response.get("Content-Type", "").split(";")[0] + return ( + not getattr(response, "streaming", False) + and content_encoding == "" + and content_type in _HTML_TYPES + ) diff --git a/docs/changes.rst b/docs/changes.rst index d47f69784..e845f3b3b 100644 --- a/docs/changes.rst +++ b/docs/changes.rst @@ -6,6 +6,7 @@ Pending * Changed ordering (and grammatical number) of panels and their titles in documentation to match actual panel ordering and titles. +* Skipped processing the alerts panel when response isn't a HTML response. 4.4.5 (2024-07-05) ------------------ From 8f4fa8e7f0a5ddc539f98fb2767b17fd568732d3 Mon Sep 17 00:00:00 2001 From: Tim Schilling Date: Wed, 10 Jul 2024 07:05:07 -0500 Subject: [PATCH 5/5] Version 4.4.6 --- README.rst | 2 +- debug_toolbar/__init__.py | 2 +- docs/changes.rst | 3 +++ docs/conf.py | 2 +- 4 files changed, 6 insertions(+), 3 deletions(-) diff --git a/README.rst b/README.rst index 4e195a796..362df2f95 100644 --- a/README.rst +++ b/README.rst @@ -44,7 +44,7 @@ Here's a screenshot of the toolbar in action: In addition to the built-in panels, a number of third-party panels are contributed by the community. -The current stable version of the Debug Toolbar is 4.4.5. It works on +The current stable version of the Debug Toolbar is 4.4.6. It works on Django ≥ 4.2.0. The Debug Toolbar does not currently support `Django's asynchronous views diff --git a/debug_toolbar/__init__.py b/debug_toolbar/__init__.py index a1a09f2a1..d98d6efae 100644 --- a/debug_toolbar/__init__.py +++ b/debug_toolbar/__init__.py @@ -4,7 +4,7 @@ # Do not use pkg_resources to find the version but set it here directly! # see issue #1446 -VERSION = "4.4.5" +VERSION = "4.4.6" # Code that discovers files or modules in INSTALLED_APPS imports this module. urls = "debug_toolbar.urls", APP_NAME diff --git a/docs/changes.rst b/docs/changes.rst index e845f3b3b..e82c598c2 100644 --- a/docs/changes.rst +++ b/docs/changes.rst @@ -4,6 +4,9 @@ Change log Pending ------- +4.4.6 (2024-07-10) +------------------ + * Changed ordering (and grammatical number) of panels and their titles in documentation to match actual panel ordering and titles. * Skipped processing the alerts panel when response isn't a HTML response. diff --git a/docs/conf.py b/docs/conf.py index 8b9d06396..924869c05 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -25,7 +25,7 @@ copyright = copyright.format(datetime.date.today().year) # The full version, including alpha/beta/rc tags -release = "4.4.5" +release = "4.4.6" # -- General configuration ---------------------------------------------------