From fa868cc43d24d8d3a71599068f51ca84c6c29eec Mon Sep 17 00:00:00 2001
From: tschilling
Date: Sat, 14 Aug 2021 09:54:00 -0500
Subject: [PATCH 01/41] Update translations and revert xgettext aliasing.
Aliasing xgettext causes the usage not to be picked up by makemessages.
Only gettext and gettext_lazy work with aliasing.
---
debug_toolbar/locale/en/LC_MESSAGES/django.po | 219 ++++++++++--------
debug_toolbar/panels/cache.py | 6 +-
debug_toolbar/panels/logging.py | 4 +-
debug_toolbar/panels/signals.py | 6 +-
debug_toolbar/panels/sql/panel.py | 14 +-
debug_toolbar/panels/staticfiles.py | 8 +-
6 files changed, 143 insertions(+), 114 deletions(-)
diff --git a/debug_toolbar/locale/en/LC_MESSAGES/django.po b/debug_toolbar/locale/en/LC_MESSAGES/django.po
index 9e58f09fd..b4d0ff233 100644
--- a/debug_toolbar/locale/en/LC_MESSAGES/django.po
+++ b/debug_toolbar/locale/en/LC_MESSAGES/django.po
@@ -6,7 +6,7 @@ msgid ""
msgstr ""
"Project-Id-Version: Django Debug Toolbar\n"
"Report-Msgid-Bugs-To: \n"
-"POT-Creation-Date: 2018-09-06 09:19+0200\n"
+"POT-Creation-Date: 2021-08-14 10:25-0500\n"
"PO-Revision-Date: 2012-03-31 20:10+0000\n"
"Last-Translator: \n"
"Language-Team: \n"
@@ -20,107 +20,111 @@ msgstr ""
msgid "Debug Toolbar"
msgstr ""
-#: panels/cache.py:188
+#: panels/cache.py:227
msgid "Cache"
msgstr ""
-#: panels/cache.py:193
+#: panels/cache.py:234
#, python-format
msgid "%(cache_calls)d call in %(time).2fms"
msgid_plural "%(cache_calls)d calls in %(time).2fms"
msgstr[0] ""
msgstr[1] ""
-#: panels/cache.py:201
+#: panels/cache.py:246
#, python-format
msgid "Cache calls from %(count)d backend"
msgid_plural "Cache calls from %(count)d backends"
msgstr[0] ""
msgstr[1] ""
-#: panels/headers.py:34
+#: panels/headers.py:33
msgid "Headers"
msgstr ""
-#: panels/logging.py:66
+#: panels/history/panel.py:20 panels/history/panel.py:21
+msgid "History"
+msgstr ""
+
+#: panels/logging.py:63
msgid "Logging"
msgstr ""
-#: panels/logging.py:72
+#: panels/logging.py:69
#, python-format
msgid "%(count)s message"
msgid_plural "%(count)s messages"
msgstr[0] ""
msgstr[1] ""
-#: panels/logging.py:75
+#: panels/logging.py:73
msgid "Log messages"
msgstr ""
-#: panels/profiling.py:148
+#: panels/profiling.py:150
msgid "Profiling"
msgstr ""
-#: panels/redirects.py:16
+#: panels/redirects.py:14
msgid "Intercept redirects"
msgstr ""
-#: panels/request.py:18
+#: panels/request.py:16
msgid "Request"
msgstr ""
-#: panels/request.py:35
+#: panels/request.py:36
msgid ""
msgstr ""
-#: panels/request.py:47
+#: panels/request.py:53
msgid ""
msgstr ""
-#: panels/settings.py:18
+#: panels/settings.py:24
msgid "Settings"
msgstr ""
-#: panels/settings.py:21
+#: panels/settings.py:27
#, python-format
-msgid "Settings from %s
"
+msgid "Settings from %s"
msgstr ""
-#: panels/signals.py:44
+#: panels/signals.py:58
#, python-format
msgid "%(num_receivers)d receiver of 1 signal"
msgid_plural "%(num_receivers)d receivers of 1 signal"
msgstr[0] ""
msgstr[1] ""
-#: panels/signals.py:47
+#: panels/signals.py:66
#, python-format
msgid "%(num_receivers)d receiver of %(num_signals)d signals"
msgid_plural "%(num_receivers)d receivers of %(num_signals)d signals"
msgstr[0] ""
msgstr[1] ""
-#: panels/signals.py:52
+#: panels/signals.py:73
msgid "Signals"
msgstr ""
-#: panels/sql/panel.py:25
+#: panels/sql/panel.py:24
msgid "Autocommit"
msgstr ""
-#: panels/sql/panel.py:26
+#: panels/sql/panel.py:25
msgid "Read uncommitted"
msgstr ""
-#: panels/sql/panel.py:27
+#: panels/sql/panel.py:26
msgid "Read committed"
msgstr ""
-#: panels/sql/panel.py:28
+#: panels/sql/panel.py:27
msgid "Repeatable read"
msgstr ""
-#: panels/sql/panel.py:29
+#: panels/sql/panel.py:28
msgid "Serializable"
msgstr ""
@@ -144,11 +148,25 @@ msgstr ""
msgid "Unknown"
msgstr ""
-#: panels/sql/panel.py:108
+#: panels/sql/panel.py:109
msgid "SQL"
msgstr ""
-#: panels/staticfiles.py:88
+#: panels/sql/panel.py:114
+#, python-format
+msgid "%(query_count)d query in %(sql_time).2fms"
+msgid_plural "%(query_count)d queries in %(sql_time).2fms"
+msgstr[0] ""
+msgstr[1] ""
+
+#: panels/sql/panel.py:127
+#, python-format
+msgid "SQL queries from %(count)d connection"
+msgid_plural "SQL queries from %(count)d connections"
+msgstr[0] ""
+msgstr[1] ""
+
+#: panels/staticfiles.py:85
#, python-format
msgid "Static files (%(num_found)s found, %(num_used)s used)"
msgstr ""
@@ -157,75 +175,76 @@ msgstr ""
msgid "Static files"
msgstr ""
-#: panels/staticfiles.py:111
+#: panels/staticfiles.py:112
#, python-format
msgid "%(num_used)s file used"
msgid_plural "%(num_used)s files used"
msgstr[0] ""
msgstr[1] ""
-#: panels/templates/panel.py:161
+#: panels/templates/panel.py:144
msgid "Templates"
msgstr ""
-#: panels/templates/panel.py:166
+#: panels/templates/panel.py:149
#, python-format
msgid "Templates (%(num_templates)s rendered)"
msgstr ""
-#: panels/templates/panel.py:198
+#: panels/templates/panel.py:181
msgid "No origin"
msgstr ""
-#: panels/timer.py:26
+#: panels/timer.py:25
#, python-format
msgid "CPU: %(cum)0.2fms (%(total)0.2fms)"
msgstr ""
-#: panels/timer.py:31
+#: panels/timer.py:30
#, python-format
msgid "Total: %0.2fms"
msgstr ""
-#: panels/timer.py:37 templates/debug_toolbar/panels/logging.html:7
+#: panels/timer.py:36 templates/debug_toolbar/panels/history.html:9
+#: templates/debug_toolbar/panels/logging.html:7
#: templates/debug_toolbar/panels/sql_explain.html:11
#: templates/debug_toolbar/panels/sql_profile.html:12
#: templates/debug_toolbar/panels/sql_select.html:11
msgid "Time"
msgstr ""
-#: panels/timer.py:45
+#: panels/timer.py:44
msgid "User CPU time"
msgstr ""
-#: panels/timer.py:45
+#: panels/timer.py:44
#, python-format
msgid "%(utime)0.3f msec"
msgstr ""
-#: panels/timer.py:46
+#: panels/timer.py:45
msgid "System CPU time"
msgstr ""
-#: panels/timer.py:46
+#: panels/timer.py:45
#, python-format
msgid "%(stime)0.3f msec"
msgstr ""
-#: panels/timer.py:47
+#: panels/timer.py:46
msgid "Total CPU time"
msgstr ""
-#: panels/timer.py:47
+#: panels/timer.py:46
#, python-format
msgid "%(total)0.3f msec"
msgstr ""
-#: panels/timer.py:48
+#: panels/timer.py:47
msgid "Elapsed time"
msgstr ""
-#: panels/timer.py:48
+#: panels/timer.py:47
#, python-format
msgid "%(total_time)0.3f msec"
msgstr ""
@@ -234,33 +253,33 @@ msgstr ""
msgid "Context switches"
msgstr ""
-#: panels/timer.py:49
+#: panels/timer.py:50
#, python-format
msgid "%(vcsw)d voluntary, %(ivcsw)d involuntary"
msgstr ""
-#: panels/versions.py:20
+#: panels/versions.py:19
msgid "Versions"
msgstr ""
-#: templates/debug_toolbar/base.html:14
+#: templates/debug_toolbar/base.html:18
msgid "Hide toolbar"
msgstr ""
-#: templates/debug_toolbar/base.html:14
+#: templates/debug_toolbar/base.html:18
msgid "Hide"
msgstr ""
-#: templates/debug_toolbar/base.html:20
-msgid "Disable for next and successive requests"
+#: templates/debug_toolbar/base.html:25
+msgid "Show toolbar"
msgstr ""
-#: templates/debug_toolbar/base.html:20
-msgid "Enable for next and successive requests"
+#: templates/debug_toolbar/includes/panel_button.html:4
+msgid "Disable for next and successive requests"
msgstr ""
-#: templates/debug_toolbar/base.html:42
-msgid "Show toolbar"
+#: templates/debug_toolbar/includes/panel_button.html:4
+msgid "Enable for next and successive requests"
msgstr ""
#: templates/debug_toolbar/panels/cache.html:2
@@ -292,7 +311,7 @@ msgid "Calls"
msgstr ""
#: templates/debug_toolbar/panels/cache.html:43
-#: templates/debug_toolbar/panels/sql.html:30
+#: templates/debug_toolbar/panels/sql.html:36
msgid "Time (ms)"
msgstr ""
@@ -327,10 +346,8 @@ msgstr ""
#: templates/debug_toolbar/panels/headers.html:9
#: templates/debug_toolbar/panels/headers.html:28
#: templates/debug_toolbar/panels/headers.html:49
-#: templates/debug_toolbar/panels/request.html:33
-#: templates/debug_toolbar/panels/request.html:59
-#: templates/debug_toolbar/panels/request.html:85
-#: templates/debug_toolbar/panels/request.html:110
+#: templates/debug_toolbar/panels/history_tr.html:23
+#: templates/debug_toolbar/panels/request_variables.html:11
#: templates/debug_toolbar/panels/settings.html:6
#: templates/debug_toolbar/panels/timer.html:11
msgid "Value"
@@ -350,6 +367,33 @@ msgid ""
"significant subset is shown below."
msgstr ""
+#: templates/debug_toolbar/panels/history.html:10
+msgid "Method"
+msgstr ""
+
+#: templates/debug_toolbar/panels/history.html:11
+#: templates/debug_toolbar/panels/staticfiles.html:43
+msgid "Path"
+msgstr ""
+
+#: templates/debug_toolbar/panels/history.html:12
+msgid "Request Variables"
+msgstr ""
+
+#: templates/debug_toolbar/panels/history.html:13
+msgid "Status"
+msgstr ""
+
+#: templates/debug_toolbar/panels/history.html:14
+#: templates/debug_toolbar/panels/sql.html:37
+msgid "Action"
+msgstr ""
+
+#: templates/debug_toolbar/panels/history_tr.html:22
+#: templates/debug_toolbar/panels/request_variables.html:10
+msgid "Variable"
+msgstr ""
+
#: templates/debug_toolbar/panels/logging.html:6
msgid "Level"
msgstr ""
@@ -408,38 +452,31 @@ msgstr ""
msgid "Cookies"
msgstr ""
-#: templates/debug_toolbar/panels/request.html:32
-#: templates/debug_toolbar/panels/request.html:58
-#: templates/debug_toolbar/panels/request.html:84
-#: templates/debug_toolbar/panels/request.html:109
-msgid "Variable"
-msgstr ""
-
-#: templates/debug_toolbar/panels/request.html:46
+#: templates/debug_toolbar/panels/request.html:27
msgid "No cookies"
msgstr ""
-#: templates/debug_toolbar/panels/request.html:50
+#: templates/debug_toolbar/panels/request.html:31
msgid "Session data"
msgstr ""
-#: templates/debug_toolbar/panels/request.html:72
+#: templates/debug_toolbar/panels/request.html:34
msgid "No session data"
msgstr ""
-#: templates/debug_toolbar/panels/request.html:76
+#: templates/debug_toolbar/panels/request.html:38
msgid "GET data"
msgstr ""
-#: templates/debug_toolbar/panels/request.html:98
+#: templates/debug_toolbar/panels/request.html:41
msgid "No GET data"
msgstr ""
-#: templates/debug_toolbar/panels/request.html:102
+#: templates/debug_toolbar/panels/request.html:45
msgid "POST data"
msgstr ""
-#: templates/debug_toolbar/panels/request.html:123
+#: templates/debug_toolbar/panels/request.html:48
msgid "No POST data"
msgstr ""
@@ -452,74 +489,66 @@ msgid "Signal"
msgstr ""
#: templates/debug_toolbar/panels/signals.html:6
-msgid "Providing"
-msgstr ""
-
-#: templates/debug_toolbar/panels/signals.html:7
msgid "Receivers"
msgstr ""
-#: templates/debug_toolbar/panels/sql.html:7
+#: templates/debug_toolbar/panels/sql.html:6
#, python-format
msgid "%(num)s query"
msgid_plural "%(num)s queries"
msgstr[0] ""
msgstr[1] ""
-#: templates/debug_toolbar/panels/sql.html:9
+#: templates/debug_toolbar/panels/sql.html:8
#, python-format
msgid ""
"including %(count)s similar"
msgstr ""
-#: templates/debug_toolbar/panels/sql.html:13
+#: templates/debug_toolbar/panels/sql.html:12
#, python-format
msgid ""
"and %(dupes)s duplicates"
msgstr ""
-#: templates/debug_toolbar/panels/sql.html:28
+#: templates/debug_toolbar/panels/sql.html:34
msgid "Query"
msgstr ""
-#: templates/debug_toolbar/panels/sql.html:29
+#: templates/debug_toolbar/panels/sql.html:35
#: templates/debug_toolbar/panels/timer.html:36
msgid "Timeline"
msgstr ""
-#: templates/debug_toolbar/panels/sql.html:31
-msgid "Action"
-msgstr ""
-
-#: templates/debug_toolbar/panels/sql.html:48
+#: templates/debug_toolbar/panels/sql.html:52
#, python-format
msgid "%(count)s similar queries."
msgstr ""
-#: templates/debug_toolbar/panels/sql.html:54
+#: templates/debug_toolbar/panels/sql.html:58
#, python-format
msgid "Duplicated %(dupes)s times."
msgstr ""
-#: templates/debug_toolbar/panels/sql.html:86
+#: templates/debug_toolbar/panels/sql.html:95
msgid "Connection:"
msgstr ""
-#: templates/debug_toolbar/panels/sql.html:88
+#: templates/debug_toolbar/panels/sql.html:97
msgid "Isolation level:"
msgstr ""
-#: templates/debug_toolbar/panels/sql.html:91
+#: templates/debug_toolbar/panels/sql.html:100
msgid "Transaction status:"
msgstr ""
-#: templates/debug_toolbar/panels/sql.html:105
+#: templates/debug_toolbar/panels/sql.html:114
msgid "(unknown)"
msgstr ""
-#: templates/debug_toolbar/panels/sql.html:114
+#: templates/debug_toolbar/panels/sql.html:123
msgid "No SQL queries were recorded during this request."
msgstr ""
@@ -594,10 +623,6 @@ msgid_plural "%(payload_count)s files"
msgstr[0] ""
msgstr[1] ""
-#: templates/debug_toolbar/panels/staticfiles.html:43
-msgid "Path"
-msgstr ""
-
#: templates/debug_toolbar/panels/template_source.html:4
msgid "Template source:"
msgstr ""
@@ -657,18 +682,18 @@ msgstr ""
msgid "Version"
msgstr ""
-#: templates/debug_toolbar/redirect.html:8
+#: templates/debug_toolbar/redirect.html:10
msgid "Location:"
msgstr ""
-#: templates/debug_toolbar/redirect.html:10
+#: templates/debug_toolbar/redirect.html:12
msgid ""
"The Django Debug Toolbar has intercepted a redirect to the above URL for "
"debug viewing purposes. You can click the above link to continue with the "
"redirect as normal."
msgstr ""
-#: views.py:16
+#: views.py:15
msgid ""
"Data for this panel isn't available anymore. Please reload the page and "
"retry."
diff --git a/debug_toolbar/panels/cache.py b/debug_toolbar/panels/cache.py
index b4c486124..0e8e190e9 100644
--- a/debug_toolbar/panels/cache.py
+++ b/debug_toolbar/panels/cache.py
@@ -19,7 +19,7 @@
from django.core.cache.backends.base import BaseCache
from django.dispatch import Signal
from django.middleware import cache as middleware_cache
-from django.utils.translation import gettext_lazy as _, ngettext as __
+from django.utils.translation import gettext_lazy as _, ngettext
from debug_toolbar import settings as dt_settings
from debug_toolbar.panels import Panel
@@ -230,7 +230,7 @@ def _store_call_info(
def nav_subtitle(self):
cache_calls = len(self.calls)
return (
- __(
+ ngettext(
"%(cache_calls)d call in %(time).2fms",
"%(cache_calls)d calls in %(time).2fms",
cache_calls,
@@ -242,7 +242,7 @@ def nav_subtitle(self):
def title(self):
count = len(getattr(settings, "CACHES", ["default"]))
return (
- __(
+ ngettext(
"Cache calls from %(count)d backend",
"Cache calls from %(count)d backends",
count,
diff --git a/debug_toolbar/panels/logging.py b/debug_toolbar/panels/logging.py
index a7252c2bb..cb0445108 100644
--- a/debug_toolbar/panels/logging.py
+++ b/debug_toolbar/panels/logging.py
@@ -1,7 +1,7 @@
import datetime
import logging
-from django.utils.translation import gettext_lazy as _, ngettext as __
+from django.utils.translation import gettext_lazy as _, ngettext
from debug_toolbar.panels import Panel
from debug_toolbar.utils import ThreadCollector
@@ -66,7 +66,7 @@ def __init__(self, *args, **kwargs):
def nav_subtitle(self):
stats = self.get_stats()
record_count = len(stats["records"]) if stats else None
- return __("%(count)s message", "%(count)s messages", record_count) % {
+ return ngettext("%(count)s message", "%(count)s messages", record_count) % {
"count": record_count
}
diff --git a/debug_toolbar/panels/signals.py b/debug_toolbar/panels/signals.py
index 4b3e7749e..3535bd143 100644
--- a/debug_toolbar/panels/signals.py
+++ b/debug_toolbar/panels/signals.py
@@ -20,7 +20,7 @@
pre_save,
)
from django.utils.module_loading import import_string
-from django.utils.translation import gettext_lazy as _, ngettext as __
+from django.utils.translation import gettext_lazy as _, ngettext
from debug_toolbar.panels import Panel
@@ -54,7 +54,7 @@ def nav_subtitle(self):
# hard coding of one signal
if num_signals == 1:
return (
- __(
+ ngettext(
"%(num_receivers)d receiver of 1 signal",
"%(num_receivers)d receivers of 1 signal",
num_receivers,
@@ -62,7 +62,7 @@ def nav_subtitle(self):
% {"num_receivers": num_receivers}
)
return (
- __(
+ ngettext(
"%(num_receivers)d receiver of %(num_signals)d signals",
"%(num_receivers)d receivers of %(num_signals)d signals",
num_receivers,
diff --git a/debug_toolbar/panels/sql/panel.py b/debug_toolbar/panels/sql/panel.py
index d15d99136..f8b92a5bd 100644
--- a/debug_toolbar/panels/sql/panel.py
+++ b/debug_toolbar/panels/sql/panel.py
@@ -5,7 +5,7 @@
from django.db import connections
from django.urls import path
-from django.utils.translation import gettext_lazy as _, ngettext_lazy as __
+from django.utils.translation import gettext_lazy as _, ngettext
from debug_toolbar.forms import SignedDataForm
from debug_toolbar.panels import Panel
@@ -110,16 +110,20 @@ def record(self, alias, **kwargs):
@property
def nav_subtitle(self):
- return __("%d query in %.2fms", "%d queries in %.2fms", self._num_queries) % (
+ return ngettext(
+ "%(query_count)d query in %(sql_time).2fms",
+ "%(query_count)d queries in %(sql_time).2fms",
self._num_queries,
- self._sql_time,
- )
+ ) % {
+ "query_count": self._num_queries,
+ "sql_time": self._sql_time,
+ }
@property
def title(self):
count = len(self._databases)
return (
- __(
+ ngettext(
"SQL queries from %(count)d connection",
"SQL queries from %(count)d connections",
count,
diff --git a/debug_toolbar/panels/staticfiles.py b/debug_toolbar/panels/staticfiles.py
index ef6af5d3e..d90b6501a 100644
--- a/debug_toolbar/panels/staticfiles.py
+++ b/debug_toolbar/panels/staticfiles.py
@@ -6,7 +6,7 @@
from django.core.checks import Warning
from django.core.files.storage import get_storage_class
from django.utils.functional import LazyObject
-from django.utils.translation import gettext_lazy as _, ngettext as __
+from django.utils.translation import gettext_lazy as _, ngettext
from debug_toolbar import panels
from debug_toolbar.utils import ThreadCollector
@@ -108,9 +108,9 @@ def num_used(self):
@property
def nav_subtitle(self):
num_used = self.num_used
- return __("%(num_used)s file used", "%(num_used)s files used", num_used) % {
- "num_used": num_used
- }
+ return ngettext(
+ "%(num_used)s file used", "%(num_used)s files used", num_used
+ ) % {"num_used": num_used}
def process_request(self, request):
collector.clear_collection()
From 6d3eb44c08f5a1668d6273aa233ecc5e09fedf26 Mon Sep 17 00:00:00 2001
From: Tim Schilling
Date: Sat, 28 Aug 2021 10:30:53 -0500
Subject: [PATCH 02/41] Utilize pre-commit to help devs follow style guidelines
(#1495)
* Utilize pre-commit to enforce style guidelines.
* Fix blanket noqa statements.
* Fix doc8 linting issues.
* Fix prettier types.
* Removing F401 violations.
---
.pre-commit-config.yaml | 46 +++++++++++++++++++
.tx/config | 1 -
LICENSE | 6 +--
debug_toolbar/locale/ca/LC_MESSAGES/django.po | 4 +-
debug_toolbar/locale/cs/LC_MESSAGES/django.po | 4 +-
debug_toolbar/locale/de/LC_MESSAGES/django.po | 4 +-
debug_toolbar/locale/en/LC_MESSAGES/django.po | 2 +-
debug_toolbar/locale/es/LC_MESSAGES/django.po | 4 +-
debug_toolbar/locale/fi/LC_MESSAGES/django.po | 4 +-
debug_toolbar/locale/fr/LC_MESSAGES/django.po | 4 +-
debug_toolbar/locale/he/LC_MESSAGES/django.po | 4 +-
debug_toolbar/locale/id/LC_MESSAGES/django.po | 4 +-
debug_toolbar/locale/nl/LC_MESSAGES/django.po | 4 +-
debug_toolbar/locale/pl/LC_MESSAGES/django.po | 4 +-
debug_toolbar/locale/pt/LC_MESSAGES/django.po | 4 +-
.../locale/pt_BR/LC_MESSAGES/django.po | 4 +-
.../locale/sv_SE/LC_MESSAGES/django.po | 4 +-
debug_toolbar/locale/uk/LC_MESSAGES/django.po | 4 +-
.../locale/zh_CN/LC_MESSAGES/django.po | 4 +-
.../management/commands/debugsqlshell.py | 7 ++-
debug_toolbar/panels/cache.py | 2 +-
debug_toolbar/panels/history/__init__.py | 4 +-
debug_toolbar/panels/sql/__init__.py | 4 +-
debug_toolbar/panels/templates/__init__.py | 4 +-
docs/changes.rst | 6 +--
docs/configuration.rst | 5 +-
docs/contributing.rst | 16 +++++--
docs/panels.rst | 20 +++++---
docs/tips.rst | 5 +-
requirements_dev.txt | 1 +
tests/panels/test_sql.py | 2 +-
31 files changed, 132 insertions(+), 59 deletions(-)
create mode 100644 .pre-commit-config.yaml
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
new file mode 100644
index 000000000..e451190d4
--- /dev/null
+++ b/.pre-commit-config.yaml
@@ -0,0 +1,46 @@
+repos:
+- repo: https://github.com/pre-commit/pre-commit-hooks
+ rev: v2.3.0
+ hooks:
+ - id: check-yaml
+ - id: end-of-file-fixer
+ - id: trailing-whitespace
+ - id: mixed-line-ending
+- repo: https://github.com/pycqa/flake8
+ rev: 3.9.2
+ hooks:
+ - id: flake8
+- repo: https://github.com/pycqa/doc8
+ rev: 0.9.0
+ hooks:
+ - id: doc8
+- repo: https://github.com/pycqa/isort
+ rev: 5.9.3
+ hooks:
+ - id: isort
+- repo: https://github.com/pre-commit/pygrep-hooks
+ rev: v1.9.0
+ hooks:
+ - id: python-check-blanket-noqa
+ - id: python-check-mock-methods
+ - id: python-no-eval
+ - id: python-no-log-warn
+ - id: rst-backticks
+ - id: rst-directive-colons
+- repo: https://github.com/pre-commit/mirrors-prettier
+ rev: v2.3.2
+ hooks:
+ - id: prettier
+ types_or: [javascript, css]
+- repo: https://github.com/pre-commit/mirrors-eslint
+ rev: v8.0.0-beta.0
+ hooks:
+ - id: eslint
+ files: \.js?$
+ types: [file]
+- repo: https://github.com/psf/black
+ rev: 21.7b0
+ hooks:
+ - id: black
+ language_version: python3
+ entry: black --target-version=py36
diff --git a/.tx/config b/.tx/config
index bdbb9bf43..5c9ecc129 100644
--- a/.tx/config
+++ b/.tx/config
@@ -6,4 +6,3 @@ lang_map = sr@latin:sr_Latn
file_filter = debug_toolbar/locale//LC_MESSAGES/django.po
source_file = debug_toolbar/locale/en/LC_MESSAGES/django.po
source_lang = en
-
diff --git a/LICENSE b/LICENSE
index 15d830926..221d73313 100644
--- a/LICENSE
+++ b/LICENSE
@@ -4,10 +4,10 @@ All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
- 1. Redistributions of source code must retain the above copyright notice,
+ 1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
-
- 2. Redistributions in binary form must reproduce the above copyright
+
+ 2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
diff --git a/debug_toolbar/locale/ca/LC_MESSAGES/django.po b/debug_toolbar/locale/ca/LC_MESSAGES/django.po
index 5de03a115..34e4007da 100644
--- a/debug_toolbar/locale/ca/LC_MESSAGES/django.po
+++ b/debug_toolbar/locale/ca/LC_MESSAGES/django.po
@@ -1,7 +1,7 @@
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package.
-#
-#
+#
+#
# Translators:
# Libre El Chaval , 2013
msgid ""
diff --git a/debug_toolbar/locale/cs/LC_MESSAGES/django.po b/debug_toolbar/locale/cs/LC_MESSAGES/django.po
index 26b6cdbdc..abb6a7c22 100644
--- a/debug_toolbar/locale/cs/LC_MESSAGES/django.po
+++ b/debug_toolbar/locale/cs/LC_MESSAGES/django.po
@@ -1,7 +1,7 @@
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package.
-#
-#
+#
+#
# Translators:
# Vlada Macek , 2013
msgid ""
diff --git a/debug_toolbar/locale/de/LC_MESSAGES/django.po b/debug_toolbar/locale/de/LC_MESSAGES/django.po
index 6ba6974f3..083a15785 100644
--- a/debug_toolbar/locale/de/LC_MESSAGES/django.po
+++ b/debug_toolbar/locale/de/LC_MESSAGES/django.po
@@ -1,7 +1,7 @@
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package.
-#
-#
+#
+#
# Translators:
# Jannis Leidel , 2012-2013
msgid ""
diff --git a/debug_toolbar/locale/en/LC_MESSAGES/django.po b/debug_toolbar/locale/en/LC_MESSAGES/django.po
index b4d0ff233..031208852 100644
--- a/debug_toolbar/locale/en/LC_MESSAGES/django.po
+++ b/debug_toolbar/locale/en/LC_MESSAGES/django.po
@@ -6,7 +6,7 @@ msgid ""
msgstr ""
"Project-Id-Version: Django Debug Toolbar\n"
"Report-Msgid-Bugs-To: \n"
-"POT-Creation-Date: 2021-08-14 10:25-0500\n"
+"POT-Creation-Date: 2021-08-23 19:54-0500\n"
"PO-Revision-Date: 2012-03-31 20:10+0000\n"
"Last-Translator: \n"
"Language-Team: \n"
diff --git a/debug_toolbar/locale/es/LC_MESSAGES/django.po b/debug_toolbar/locale/es/LC_MESSAGES/django.po
index f7d763e1e..d348645e4 100644
--- a/debug_toolbar/locale/es/LC_MESSAGES/django.po
+++ b/debug_toolbar/locale/es/LC_MESSAGES/django.po
@@ -1,7 +1,7 @@
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package.
-#
-#
+#
+#
# Translators:
# jcatalan , 2014
# Leonardo J. Caballero G. , 2013-2014
diff --git a/debug_toolbar/locale/fi/LC_MESSAGES/django.po b/debug_toolbar/locale/fi/LC_MESSAGES/django.po
index 7e27b07d4..97d8bdcbd 100644
--- a/debug_toolbar/locale/fi/LC_MESSAGES/django.po
+++ b/debug_toolbar/locale/fi/LC_MESSAGES/django.po
@@ -1,7 +1,7 @@
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package.
-#
-#
+#
+#
# Translators:
# nanook , 2012
msgid ""
diff --git a/debug_toolbar/locale/fr/LC_MESSAGES/django.po b/debug_toolbar/locale/fr/LC_MESSAGES/django.po
index 586811144..4ce0574f3 100644
--- a/debug_toolbar/locale/fr/LC_MESSAGES/django.po
+++ b/debug_toolbar/locale/fr/LC_MESSAGES/django.po
@@ -1,7 +1,7 @@
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package.
-#
-#
+#
+#
# Translators:
# Pingax , 2013
# claudep , 2013
diff --git a/debug_toolbar/locale/he/LC_MESSAGES/django.po b/debug_toolbar/locale/he/LC_MESSAGES/django.po
index 66f13742f..2afad7e72 100644
--- a/debug_toolbar/locale/he/LC_MESSAGES/django.po
+++ b/debug_toolbar/locale/he/LC_MESSAGES/django.po
@@ -1,7 +1,7 @@
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package.
-#
-#
+#
+#
# Translators:
# shaib , 2012
msgid ""
diff --git a/debug_toolbar/locale/id/LC_MESSAGES/django.po b/debug_toolbar/locale/id/LC_MESSAGES/django.po
index 8589fb5f6..386fda1ee 100644
--- a/debug_toolbar/locale/id/LC_MESSAGES/django.po
+++ b/debug_toolbar/locale/id/LC_MESSAGES/django.po
@@ -1,7 +1,7 @@
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package.
-#
-#
+#
+#
# Translators:
# Muhammad Panji , 2012
msgid ""
diff --git a/debug_toolbar/locale/nl/LC_MESSAGES/django.po b/debug_toolbar/locale/nl/LC_MESSAGES/django.po
index 07b95546b..ccbb4c318 100644
--- a/debug_toolbar/locale/nl/LC_MESSAGES/django.po
+++ b/debug_toolbar/locale/nl/LC_MESSAGES/django.po
@@ -1,7 +1,7 @@
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package.
-#
-#
+#
+#
# Translators:
# Ingo Berben , 2012-2013
msgid ""
diff --git a/debug_toolbar/locale/pl/LC_MESSAGES/django.po b/debug_toolbar/locale/pl/LC_MESSAGES/django.po
index 0d674f1aa..2e9942a15 100644
--- a/debug_toolbar/locale/pl/LC_MESSAGES/django.po
+++ b/debug_toolbar/locale/pl/LC_MESSAGES/django.po
@@ -1,7 +1,7 @@
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package.
-#
-#
+#
+#
# Translators:
# Konrad Mosoń , 2013
msgid ""
diff --git a/debug_toolbar/locale/pt/LC_MESSAGES/django.po b/debug_toolbar/locale/pt/LC_MESSAGES/django.po
index 038fdec7b..58a793ad0 100644
--- a/debug_toolbar/locale/pt/LC_MESSAGES/django.po
+++ b/debug_toolbar/locale/pt/LC_MESSAGES/django.po
@@ -1,7 +1,7 @@
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package.
-#
-#
+#
+#
# Translators:
# joseduraes , 2014
msgid ""
diff --git a/debug_toolbar/locale/pt_BR/LC_MESSAGES/django.po b/debug_toolbar/locale/pt_BR/LC_MESSAGES/django.po
index ed25331b6..705dd7fa7 100644
--- a/debug_toolbar/locale/pt_BR/LC_MESSAGES/django.po
+++ b/debug_toolbar/locale/pt_BR/LC_MESSAGES/django.po
@@ -1,7 +1,7 @@
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package.
-#
-#
+#
+#
# Translators:
# Fábio , 2013-2014
# Percy Pérez-Pinedo, 2009
diff --git a/debug_toolbar/locale/sv_SE/LC_MESSAGES/django.po b/debug_toolbar/locale/sv_SE/LC_MESSAGES/django.po
index 0c8b2e897..a29096e6f 100644
--- a/debug_toolbar/locale/sv_SE/LC_MESSAGES/django.po
+++ b/debug_toolbar/locale/sv_SE/LC_MESSAGES/django.po
@@ -1,7 +1,7 @@
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package.
-#
-#
+#
+#
# Translators:
# Alex Nordlund , 2012-2013
# Alex Nordlund , 2012
diff --git a/debug_toolbar/locale/uk/LC_MESSAGES/django.po b/debug_toolbar/locale/uk/LC_MESSAGES/django.po
index 9a642f694..11bdf68ff 100644
--- a/debug_toolbar/locale/uk/LC_MESSAGES/django.po
+++ b/debug_toolbar/locale/uk/LC_MESSAGES/django.po
@@ -1,7 +1,7 @@
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package.
-#
-#
+#
+#
# Translators:
# Sergey Lysach , 2013
msgid ""
diff --git a/debug_toolbar/locale/zh_CN/LC_MESSAGES/django.po b/debug_toolbar/locale/zh_CN/LC_MESSAGES/django.po
index 521d57761..44993f554 100644
--- a/debug_toolbar/locale/zh_CN/LC_MESSAGES/django.po
+++ b/debug_toolbar/locale/zh_CN/LC_MESSAGES/django.po
@@ -1,7 +1,7 @@
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package.
-#
-#
+#
+#
# Translators:
# mozillazg , 2013-2014
msgid ""
diff --git a/debug_toolbar/management/commands/debugsqlshell.py b/debug_toolbar/management/commands/debugsqlshell.py
index 78e09e27d..ba0f32463 100644
--- a/debug_toolbar/management/commands/debugsqlshell.py
+++ b/debug_toolbar/management/commands/debugsqlshell.py
@@ -2,7 +2,7 @@
import django
import sqlparse
-from django.core.management.commands.shell import Command # noqa
+from django.core.management.commands.shell import Command
from django.db import connection
if connection.vendor == "postgresql" and django.VERSION >= (3, 0, 0):
@@ -13,6 +13,11 @@
# 'debugsqlshell' is the same as the 'shell'.
+# Command is required to exist to be loaded via
+# django.core.managementload_command_class
+__all__ = ["Command", "PrintQueryWrapper"]
+
+
class PrintQueryWrapper(base_module.CursorDebugWrapper):
def execute(self, sql, params=()):
start_time = time()
diff --git a/debug_toolbar/panels/cache.py b/debug_toolbar/panels/cache.py
index 0e8e190e9..0b2af6ee4 100644
--- a/debug_toolbar/panels/cache.py
+++ b/debug_toolbar/panels/cache.py
@@ -109,7 +109,7 @@ def clear(self, *args, **kwargs):
def has_key(self, *args, **kwargs):
# Ignore flake8 rules for has_key since we need to support caches
# that may be using has_key.
- return self.cache.has_key(*args, **kwargs) # noqa
+ return self.cache.has_key(*args, **kwargs) # noqa: W601
@send_signal
def incr(self, *args, **kwargs):
diff --git a/debug_toolbar/panels/history/__init__.py b/debug_toolbar/panels/history/__init__.py
index 78c876b81..52ceb7984 100644
--- a/debug_toolbar/panels/history/__init__.py
+++ b/debug_toolbar/panels/history/__init__.py
@@ -1 +1,3 @@
-from debug_toolbar.panels.history.panel import HistoryPanel # noqa
+from debug_toolbar.panels.history.panel import HistoryPanel
+
+__all__ = ["HistoryPanel"]
diff --git a/debug_toolbar/panels/sql/__init__.py b/debug_toolbar/panels/sql/__init__.py
index a4f9cd4bf..46c68a3c6 100644
--- a/debug_toolbar/panels/sql/__init__.py
+++ b/debug_toolbar/panels/sql/__init__.py
@@ -1 +1,3 @@
-from debug_toolbar.panels.sql.panel import SQLPanel # noqa
+from debug_toolbar.panels.sql.panel import SQLPanel
+
+__all__ = ["SQLPanel"]
diff --git a/debug_toolbar/panels/templates/__init__.py b/debug_toolbar/panels/templates/__init__.py
index 1f768f57b..a1d509b9e 100644
--- a/debug_toolbar/panels/templates/__init__.py
+++ b/debug_toolbar/panels/templates/__init__.py
@@ -1 +1,3 @@
-from debug_toolbar.panels.templates.panel import TemplatesPanel # noqa
+from debug_toolbar.panels.templates.panel import TemplatesPanel
+
+__all__ = ["TemplatesPanel"]
diff --git a/docs/changes.rst b/docs/changes.rst
index 1a322752e..7dd52713c 100644
--- a/docs/changes.rst
+++ b/docs/changes.rst
@@ -371,9 +371,9 @@ This version is compatible with Django 1.9 and requires Django 1.7 or later.
New features
~~~~~~~~~~~~
-* New panel method :meth:`debug_toolbar.panels.Panel.generate_stats` allows panels
- to only record stats when the toolbar is going to be inserted into the
- response.
+* New panel method :meth:`debug_toolbar.panels.Panel.generate_stats` allows
+ panels to only record stats when the toolbar is going to be inserted into
+ the response.
Bug fixes
~~~~~~~~~
diff --git a/docs/configuration.rst b/docs/configuration.rst
index 0d7cd87c4..96758d89c 100644
--- a/docs/configuration.rst
+++ b/docs/configuration.rst
@@ -201,7 +201,10 @@ Panel options
**Without grouping**::
- SELECT "auth_user"."id", "auth_user"."password", "auth_user"."last_login", "auth_user"."is_superuser", "auth_user"."username", "auth_user"."first_name", "auth_user"."last_name"
+ SELECT
+ "auth_user"."id", "auth_user"."password", "auth_user"."last_login",
+ "auth_user"."is_superuser", "auth_user"."username", "auth_user"."first_name",
+ "auth_user"."last_name"
FROM "auth_user"
WHERE "auth_user"."username" = '''test_username'''
LIMIT 21
diff --git a/docs/contributing.rst b/docs/contributing.rst
index 245159a52..cbb147002 100644
--- a/docs/contributing.rst
+++ b/docs/contributing.rst
@@ -79,8 +79,8 @@ or by setting the ``DJANGO_SELENIUM_TESTS`` environment variable::
$ DJANGO_SELENIUM_TESTS=true make coverage
$ DJANGO_SELENIUM_TESTS=true tox
-To test via `tox` against other databases, you'll need to create the user,
-database and assign the proper permissions. For PostgreSQL in a `psql`
+To test via ``tox`` against other databases, you'll need to create the user,
+database and assign the proper permissions. For PostgreSQL in a ``psql``
shell (note this allows the debug_toolbar user the permission to create
databases)::
@@ -89,7 +89,7 @@ databases)::
psql> CREATE DATABASE debug_toolbar;
psql> GRANT ALL PRIVILEGES ON DATABASE debug_toolbar to debug_toolbar;
-For MySQL/MariaDB in a `mysql` shell::
+For MySQL/MariaDB in a ``mysql`` shell::
mysql> CREATE DATABASE debug_toolbar;
mysql> CREATE USER 'debug_toolbar'@'localhost' IDENTIFIED BY 'debug_toolbar';
@@ -101,8 +101,14 @@ Style
-----
The Django Debug Toolbar uses `black `__ to
-format code and additionally uses flake8 and isort. You can reformat the code
-using::
+format code and additionally uses flake8 and isort. The toolbar uses
+`pre-commit `__ to automatically apply our style guidelines
+when a commit is made. If necessary this can be bypassed using::
+
+ $ git commit --no-verify
+
+
+To reformat the code manually use::
$ make style
diff --git a/docs/panels.rst b/docs/panels.rst
index a836054ed..b555b92d5 100644
--- a/docs/panels.rst
+++ b/docs/panels.rst
@@ -220,7 +220,8 @@ Memcache
URL: https://github.com/ross/memcache-debug-panel
-Path: ``memcache_toolbar.panels.memcache.MemcachePanel`` or ``memcache_toolbar.panels.pylibmc.PylibmcPanel``
+Path: ``memcache_toolbar.panels.memcache.MemcachePanel`` or
+``memcache_toolbar.panels.pylibmc.PylibmcPanel``
This panel tracks memcached usage. It currently supports both the pylibmc and
memcache libraries.
@@ -241,7 +242,8 @@ URL: https://github.com/robinedwards/django-debug-toolbar-neo4j-panel
Path: ``neo4j_panel.Neo4jPanel``
-Trace neo4j rest API calls in your Django application, this also works for neo4django and neo4jrestclient, support for py2neo is on its way.
+Trace neo4j rest API calls in your Django application, this also works for
+neo4django and neo4jrestclient, support for py2neo is on its way.
Pympler
~~~~~~~
@@ -250,7 +252,8 @@ URL: https://pythonhosted.org/Pympler/django.html
Path: ``pympler.panels.MemoryPanel``
-Shows process memory information (virtual size, resident set size) and model instances for the current request.
+Shows process memory information (virtual size, resident set size) and model
+instances for the current request.
Request History
~~~~~~~~~~~~~~~
@@ -259,7 +262,8 @@ URL: https://github.com/djsutho/django-debug-toolbar-request-history
Path: ``ddt_request_history.panels.request_history.RequestHistoryPanel``
-Switch between requests to view their stats. Also adds support for viewing stats for AJAX requests.
+Switch between requests to view their stats. Also adds support for viewing
+stats for AJAX requests.
Requests
~~~~~~~~
@@ -289,8 +293,9 @@ URL: https://github.com/node13h/django-debug-toolbar-template-profiler
Path: ``template_profiler_panel.panels.template.TemplateProfilerPanel``
-Shows template render call duration and distribution on the timeline. Lightweight.
-Compatible with WSGI servers which reuse threads for multiple requests (Werkzeug).
+Shows template render call duration and distribution on the timeline.
+Lightweight. Compatible with WSGI servers which reuse threads for multiple
+requests (Werkzeug).
Template Timings
~~~~~~~~~~~~~~~~
@@ -317,7 +322,8 @@ URL: https://github.com/giginet/django-debug-toolbar-vcs-info
Path: ``vcs_info_panel.panels.GitInfoPanel``
-Displays VCS status (revision, branch, latest commit log and more) of your Django application.
+Displays VCS status (revision, branch, latest commit log and more) of your
+Django application.
uWSGI Stats
~~~~~~~~~~~
diff --git a/docs/tips.rst b/docs/tips.rst
index f7a31e927..e6957b0c6 100644
--- a/docs/tips.rst
+++ b/docs/tips.rst
@@ -51,8 +51,9 @@ development.
The cache panel is very similar to the SQL panel, except it isn't always a bad
practice to make many cache queries in a view.
-The template panel becomes slow if your views or context processors return large
-contexts and your templates have complex inheritance or inclusion schemes.
+The template panel becomes slow if your views or context processors return
+large contexts and your templates have complex inheritance or inclusion
+schemes.
Solutions
~~~~~~~~~
diff --git a/requirements_dev.txt b/requirements_dev.txt
index 6010ea4f7..fd82925d9 100644
--- a/requirements_dev.txt
+++ b/requirements_dev.txt
@@ -21,5 +21,6 @@ sphinxcontrib-spelling
# Other tools
+pre-commit
transifex-client
wheel
diff --git a/tests/panels/test_sql.py b/tests/panels/test_sql.py
index 08535a79e..6ca241f41 100644
--- a/tests/panels/test_sql.py
+++ b/tests/panels/test_sql.py
@@ -273,7 +273,7 @@ def test_insert_locals(self):
"""
Test that the panel inserts locals() content.
"""
- local_var = "" # noqa
+ local_var = "" # noqa: F841
list(User.objects.filter(username="café".encode("utf-8")))
response = self.panel.process_request(self.request)
self.panel.generate_stats(self.request, response)
From 6cc626562f17c91b1ce2568b671f0fff0866439e Mon Sep 17 00:00:00 2001
From: Tim Schilling
Date: Sat, 28 Aug 2021 10:43:00 -0500
Subject: [PATCH 03/41] Changed cache monkey-patching for Django 3.2+ (#1497)
* Changed cache monkey-patching for Django 3.2+
Changed cache monkey-patching for Django 3.2+ to iterate over existing
caches and patch them individually rather than attempting to patch
django.core.caches as a whole. The middleware.cache is still
being patched as a whole in order to attempt to catch any cache
usages before enable_instrumentation is called.
Test cache panel is disabled for middleware before it.
* Apply suggestions from code review
Co-authored-by: Matthias Kestenholz
---
debug_toolbar/panels/cache.py | 62 +++++++++++++++++++++++++++--------
docs/changes.rst | 6 ++++
tests/middleware.py | 17 ++++++++++
tests/settings.py | 1 +
tests/test_integration.py | 22 ++++++++++++-
tests/urls.py | 1 +
tests/views.py | 10 ++++++
7 files changed, 105 insertions(+), 14 deletions(-)
create mode 100644 tests/middleware.py
diff --git a/debug_toolbar/panels/cache.py b/debug_toolbar/panels/cache.py
index 0b2af6ee4..41063c573 100644
--- a/debug_toolbar/panels/cache.py
+++ b/debug_toolbar/panels/cache.py
@@ -8,6 +8,7 @@
except ImportError:
ConnectionProxy = None
+import django
from django.conf import settings
from django.core import cache
from django.core.cache import (
@@ -140,10 +141,27 @@ def decr_version(self, *args, **kwargs):
return self.cache.decr_version(*args, **kwargs)
-class CacheHandlerPatch(CacheHandler):
- def __getitem__(self, alias):
- actual_cache = super().__getitem__(alias)
- return CacheStatTracker(actual_cache)
+if django.VERSION < (3, 2):
+
+ class CacheHandlerPatch(CacheHandler):
+ def __getitem__(self, alias):
+ actual_cache = super().__getitem__(alias)
+ return CacheStatTracker(actual_cache)
+
+
+else:
+
+ class CacheHandlerPatch(CacheHandler):
+ def __init__(self, settings=None):
+ self._djdt_wrap = True
+ super().__init__(settings=settings)
+
+ def create_connection(self, alias):
+ actual_cache = super().create_connection(alias)
+ if self._djdt_wrap:
+ return CacheStatTracker(actual_cache)
+ else:
+ return actual_cache
middleware_cache.caches = CacheHandlerPatch()
@@ -251,22 +269,40 @@ def title(self):
)
def enable_instrumentation(self):
- if isinstance(middleware_cache.caches, CacheHandlerPatch):
- cache.caches = middleware_cache.caches
+ if django.VERSION < (3, 2):
+ if isinstance(middleware_cache.caches, CacheHandlerPatch):
+ cache.caches = middleware_cache.caches
+ else:
+ cache.caches = CacheHandlerPatch()
else:
- cache.caches = CacheHandlerPatch()
+ for alias in cache.caches:
+ if not isinstance(cache.caches[alias], CacheStatTracker):
+ cache.caches[alias] = CacheStatTracker(cache.caches[alias])
+
+ if not isinstance(middleware_cache.caches, CacheHandlerPatch):
+ middleware_cache.caches = cache.caches
# Wrap the patched cache inside Django's ConnectionProxy
if ConnectionProxy:
cache.cache = ConnectionProxy(cache.caches, DEFAULT_CACHE_ALIAS)
def disable_instrumentation(self):
- cache.caches = original_caches
- cache.cache = original_cache
- # While it can be restored to the original, any views that were
- # wrapped with the cache_page decorator will continue to use a
- # monkey patched cache.
- middleware_cache.caches = original_caches
+ if django.VERSION < (3, 2):
+ cache.caches = original_caches
+ cache.cache = original_cache
+ # While it can be restored to the original, any views that were
+ # wrapped with the cache_page decorator will continue to use a
+ # monkey patched cache.
+ middleware_cache.caches = original_caches
+ else:
+ for alias in cache.caches:
+ if isinstance(cache.caches[alias], CacheStatTracker):
+ cache.caches[alias] = cache.caches[alias].cache
+ if ConnectionProxy:
+ cache.cache = ConnectionProxy(cache.caches, DEFAULT_CACHE_ALIAS)
+ # While it can be restored to the original, any views that were
+ # wrapped with the cache_page decorator will continue to use a
+ # monkey patched cache.
def generate_stats(self, request, response):
self.record_stats(
diff --git a/docs/changes.rst b/docs/changes.rst
index 7dd52713c..f2b4f30a7 100644
--- a/docs/changes.rst
+++ b/docs/changes.rst
@@ -4,6 +4,12 @@ Change log
Next version
------------
+* Changed cache monkey-patching for Django 3.2+ to iterate over existing
+ caches and patch them individually rather than attempting to patch
+ ``django.core.caches`` as a whole. The ``middleware.cache`` is still
+ being patched as a whole in order to attempt to catch any cache
+ usages before ``enable_instrumentation`` is called.
+
3.2.2 (2021-08-14)
------------------
diff --git a/tests/middleware.py b/tests/middleware.py
new file mode 100644
index 000000000..ce46e2066
--- /dev/null
+++ b/tests/middleware.py
@@ -0,0 +1,17 @@
+from django.core.cache import cache
+
+
+class UseCacheAfterToolbar:
+ """
+ This middleware exists to use the cache before and after
+ the toolbar is setup.
+ """
+
+ def __init__(self, get_response):
+ self.get_response = get_response
+
+ def __call__(self, request):
+ cache.set("UseCacheAfterToolbar.before", 1)
+ response = self.get_response(request)
+ cache.set("UseCacheAfterToolbar.after", 1)
+ return response
diff --git a/tests/settings.py b/tests/settings.py
index b7ca35faf..2a4b5e68c 100644
--- a/tests/settings.py
+++ b/tests/settings.py
@@ -30,6 +30,7 @@
MEDIA_URL = "/media/" # Avoids https://code.djangoproject.com/ticket/21451
MIDDLEWARE = [
+ "tests.middleware.UseCacheAfterToolbar",
"debug_toolbar.middleware.DebugToolbarMiddleware",
"django.middleware.security.SecurityMiddleware",
"django.contrib.sessions.middleware.SessionMiddleware",
diff --git a/tests/test_integration.py b/tests/test_integration.py
index 6d3208fff..3be1ef589 100644
--- a/tests/test_integration.py
+++ b/tests/test_integration.py
@@ -6,6 +6,7 @@
import html5lib
from django.contrib.staticfiles.testing import StaticLiveServerTestCase
from django.core import signing
+from django.core.cache import cache
from django.db import connection
from django.http import HttpResponse
from django.template.loader import get_template
@@ -102,6 +103,25 @@ def test_cache_page(self):
self.client.get("/cached_view/")
self.assertEqual(len(self.toolbar.get_panel_by_id("CachePanel").calls), 5)
+ def test_low_level_cache_view(self):
+ """Test cases when low level caching API is used within a request."""
+ self.client.get("/cached_low_level_view/")
+ self.assertEqual(len(self.toolbar.get_panel_by_id("CachePanel").calls), 2)
+ self.client.get("/cached_low_level_view/")
+ self.assertEqual(len(self.toolbar.get_panel_by_id("CachePanel").calls), 3)
+
+ def test_cache_disable_instrumentation(self):
+ """
+ Verify that middleware cache usages before and after
+ DebugToolbarMiddleware are not counted.
+ """
+ self.assertIsNone(cache.set("UseCacheAfterToolbar.before", None))
+ self.assertIsNone(cache.set("UseCacheAfterToolbar.after", None))
+ self.client.get("/execute_sql/")
+ self.assertEqual(cache.get("UseCacheAfterToolbar.before"), 1)
+ self.assertEqual(cache.get("UseCacheAfterToolbar.after"), 1)
+ self.assertEqual(len(self.toolbar.get_panel_by_id("CachePanel").calls), 0)
+
def test_is_toolbar_request(self):
self.request.path = "/__debug__/render_panel/"
self.assertTrue(self.toolbar.is_toolbar_request(self.request))
@@ -376,7 +396,7 @@ def test_view_returns_template_response(self):
self.assertEqual(response.status_code, 200)
@override_settings(DEBUG_TOOLBAR_CONFIG={"DISABLE_PANELS": set()})
- def test_incercept_redirects(self):
+ def test_intcercept_redirects(self):
response = self.client.get("/redirect/")
self.assertEqual(response.status_code, 200)
# Link to LOCATION header.
diff --git a/tests/urls.py b/tests/urls.py
index cef00e3e2..b82dec6b1 100644
--- a/tests/urls.py
+++ b/tests/urls.py
@@ -20,6 +20,7 @@
path("new_user/", views.new_user),
path("execute_sql/", views.execute_sql),
path("cached_view/", views.cached_view),
+ path("cached_low_level_view/", views.cached_low_level_view),
path("json_view/", views.json_view),
path("redirect/", views.redirect_view),
path("login_without_redirect/", LoginView.as_view(redirect_field_name=None)),
diff --git a/tests/views.py b/tests/views.py
index 15c0c18ec..b2fd21c54 100644
--- a/tests/views.py
+++ b/tests/views.py
@@ -1,4 +1,5 @@
from django.contrib.auth.models import User
+from django.core.cache import cache
from django.http import HttpResponseRedirect, JsonResponse
from django.shortcuts import render
from django.template.response import TemplateResponse
@@ -33,6 +34,15 @@ def cached_view(request):
return render(request, "base.html")
+def cached_low_level_view(request):
+ key = "spam"
+ value = cache.get(key)
+ if not value:
+ value = "eggs"
+ cache.set(key, value, 60)
+ return render(request, "base.html")
+
+
def json_view(request):
return JsonResponse({"foo": "bar"})
From e20ac73bd8074d2dbced6e7ed14b3bd55e526669 Mon Sep 17 00:00:00 2001
From: Tim Schilling
Date: Sat, 28 Aug 2021 16:52:59 -0500
Subject: [PATCH 04/41] Add check and docs for TEMPLATES APP_DIRS=False.
(#1498)
* Add check and docs for TEMPLATES APP_DIRS=False.
The toolbar requires at least one DjangoTemplates TEMPLATES
configuration needs to have APP_DIRS set to True.
---
debug_toolbar/apps.py | 14 ++++++++++++++
docs/changes.rst | 2 ++
docs/checks.rst | 2 ++
docs/installation.rst | 5 +++++
tests/test_checks.py | 34 ++++++++++++++++++++++++++++++++++
5 files changed, 57 insertions(+)
diff --git a/debug_toolbar/apps.py b/debug_toolbar/apps.py
index eec750a3b..69464c64d 100644
--- a/debug_toolbar/apps.py
+++ b/debug_toolbar/apps.py
@@ -23,6 +23,20 @@ def check_middleware(app_configs, **kwargs):
gzip_index = None
debug_toolbar_indexes = []
+ if all(not config.get("APP_DIRS", False) for config in settings.TEMPLATES):
+ errors.append(
+ Warning(
+ "At least one DjangoTemplates TEMPLATES configuration needs "
+ "to have APP_DIRS set to True.",
+ hint=(
+ "Use APP_DIRS=True for at least one "
+ "django.template.backends.django.DjangoTemplates "
+ "backend configuration."
+ ),
+ id="debug_toolbar.W006",
+ )
+ )
+
# If old style MIDDLEWARE_CLASSES is being used, report an error.
if settings.is_overridden("MIDDLEWARE_CLASSES"):
errors.append(
diff --git a/docs/changes.rst b/docs/changes.rst
index f2b4f30a7..1a1a654e4 100644
--- a/docs/changes.rst
+++ b/docs/changes.rst
@@ -9,6 +9,8 @@ Next version
``django.core.caches`` as a whole. The ``middleware.cache`` is still
being patched as a whole in order to attempt to catch any cache
usages before ``enable_instrumentation`` is called.
+* Add check ``W006`` to warn that the toolbar is incompatible with
+ ``TEMPLATES`` settings configurations with ``APP_DIRS`` set to ``False``.
3.2.2 (2021-08-14)
diff --git a/docs/checks.rst b/docs/checks.rst
index 8575ed565..4d4882db6 100644
--- a/docs/checks.rst
+++ b/docs/checks.rst
@@ -14,3 +14,5 @@ Debug Toolbar setup and configuration:
* **debug_toolbar.W004**: ``debug_toolbar`` is incompatible with
``MIDDLEWARE_CLASSES`` setting.
* **debug_toolbar.W005**: Setting ``DEBUG_TOOLBAR_PANELS`` is empty.
+* **debug_toolbar.W006**: At least one ``DjangoTemplates`` ``TEMPLATES``
+ configuration needs to have ``APP_DIRS`` set to ``True``.
diff --git a/docs/installation.rst b/docs/installation.rst
index 4eff7fc89..27a6b6b85 100644
--- a/docs/installation.rst
+++ b/docs/installation.rst
@@ -37,6 +37,11 @@ Make sure that ``'django.contrib.staticfiles'`` is `set up properly
STATIC_URL = '/static/'
+Make sure your ``TEMPLATES`` setting contains a ``DjangoTemplates`` backend
+whose ``APP_DIRS`` options is set to ``True``. It's in there by default, so
+you'll only need to change this if you've changed that setting.
+
+
If you're upgrading from a previous version, you should review the
:doc:`change log ` and look for specific upgrade instructions.
diff --git a/tests/test_checks.py b/tests/test_checks.py
index a1c59614a..15464f9a2 100644
--- a/tests/test_checks.py
+++ b/tests/test_checks.py
@@ -122,3 +122,37 @@ def test_panels_is_empty(self):
)
],
)
+
+ @override_settings(
+ TEMPLATES=[
+ {
+ "BACKEND": "django.template.backends.django.DjangoTemplates",
+ "APP_DIRS": False,
+ "OPTIONS": {
+ "context_processors": [
+ "django.template.context_processors.debug",
+ "django.template.context_processors.request",
+ "django.contrib.auth.context_processors.auth",
+ "django.contrib.messages.context_processors.messages",
+ ]
+ },
+ },
+ ]
+ )
+ def test_templates_is_using_app_dirs_false(self):
+ errors = run_checks()
+ self.assertEqual(
+ errors,
+ [
+ Warning(
+ "At least one DjangoTemplates TEMPLATES configuration "
+ "needs to have APP_DIRS set to True.",
+ hint=(
+ "Use APP_DIRS=True for at least one "
+ "django.template.backends.django.DjangoTemplates "
+ "backend configuration."
+ ),
+ id="debug_toolbar.W006",
+ )
+ ],
+ )
From d779328b19ef9c7835be1c80acedca752a67f3e8 Mon Sep 17 00:00:00 2001
From: Tim Schilling
Date: Sun, 12 Sep 2021 10:45:59 -0500
Subject: [PATCH 05/41] Update tox and github actions. (#1500)
- Test with python 3.10
- Switch selenium test to py3.9 and django 3.2
- Use latest versions of mariadb and postgresql in CI
---
.github/workflows/test.yml | 10 +++++-----
tox.ini | 10 ++++++----
2 files changed, 11 insertions(+), 9 deletions(-)
diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml
index 667846cdc..5ab3122fd 100644
--- a/.github/workflows/test.yml
+++ b/.github/workflows/test.yml
@@ -9,11 +9,11 @@ jobs:
fail-fast: false
max-parallel: 5
matrix:
- python-version: ['3.6', '3.7', '3.8', '3.9']
+ python-version: ['3.6', '3.7', '3.8', '3.9', '3.10.0-rc.1']
services:
mariadb:
- image: mariadb:10.3
+ image: mariadb
env:
MYSQL_ROOT_PASSWORD: debug_toolbar
options: >-
@@ -76,11 +76,11 @@ jobs:
fail-fast: false
max-parallel: 5
matrix:
- python-version: ['3.6', '3.7', '3.8', '3.9']
+ python-version: ['3.6', '3.7', '3.8', '3.9', '3.10.0-rc.1']
services:
postgres:
- image: 'postgres:9.5'
+ image: postgres
env:
POSTGRES_DB: debug_toolbar
POSTGRES_USER: debug_toolbar
@@ -143,7 +143,7 @@ jobs:
fail-fast: false
max-parallel: 5
matrix:
- python-version: ['3.6', '3.7', '3.8', '3.9']
+ python-version: ['3.6', '3.7', '3.8', '3.9', '3.10.0-rc.1']
steps:
- uses: actions/checkout@v2
diff --git a/tox.ini b/tox.ini
index c3bb0bac2..e65718d29 100644
--- a/tox.ini
+++ b/tox.ini
@@ -6,6 +6,7 @@ envlist =
py{36,37}-dj{22,31,32}-sqlite
py{38,39}-dj{22,31,32,main}-sqlite
py{36,37,38,39}-dj{22,31,32}-{postgresql,mysql}
+ py{310}-dj{32,main}-{sqlite,postgresql,mysql}
[testenv]
deps =
@@ -33,7 +34,7 @@ passenv=
setenv =
PYTHONPATH = {toxinidir}
PYTHONWARNINGS = d
- py38-dj31-postgresql: DJANGO_SELENIUM_TESTS = true
+ py39-dj32-postgresql: DJANGO_SELENIUM_TESTS = true
DB_NAME = {env:DB_NAME:debug_toolbar}
DB_USER = {env:DB_USER:debug_toolbar}
DB_HOST = {env:DB_HOST:localhost}
@@ -42,19 +43,19 @@ whitelist_externals = make
pip_pre = True
commands = make coverage TEST_ARGS='{posargs:tests}'
-[testenv:py{36,37,38,39}-dj{22,31,32}-postgresql]
+[testenv:py{36,37,38,39,310}-dj{22,31,32}-postgresql]
setenv =
{[testenv]setenv}
DB_BACKEND = postgresql
DB_PORT = {env:DB_PORT:5432}
-[testenv:py{36,37,38,39}-dj{22,31,32}-mysql]
+[testenv:py{36,37,38,39,310}-dj{22,31,32}-mysql]
setenv =
{[testenv]setenv}
DB_BACKEND = mysql
DB_PORT = {env:DB_PORT:3306}
-[testenv:py{36,37,38,39}-dj{22,31,32,main}-sqlite]
+[testenv:py{36,37,38,39,310}-dj{22,31,32,main}-sqlite]
setenv =
{[testenv]setenv}
DB_BACKEND = sqlite3
@@ -90,6 +91,7 @@ python =
3.7: py37
3.8: py38
3.9: py39
+ 3.10: py310
[gh-actions:env]
DB_BACKEND =
From 1a3cabac1c3d9b98b0d024a1bb907f20f487c5cf Mon Sep 17 00:00:00 2001
From: Matthias Kestenholz
Date: Tue, 28 Sep 2021 09:20:00 +0200
Subject: [PATCH 06/41] Possibly fix an infinite recursion crash by avoid str()
inside repr() (#1507)
See https://code.djangoproject.com/ticket/33134
---
tests/forms.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tests/forms.py b/tests/forms.py
index 916cb6612..9a4d38769 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 str(self)
+ return repr(self)
From 1a5a761f643891862087978278bb44ff1f7378dc Mon Sep 17 00:00:00 2001
From: Matthias Kestenholz
Date: Tue, 28 Sep 2021 09:52:46 +0200
Subject: [PATCH 07/41] Add Django 4.0a1 to tox.ini (#1508)
* Add Django 4.0a1 to tox.ini
* Rewrite the tox.ini matrix
Thanks @felixmm!
---
tox.ini | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/tox.ini b/tox.ini
index e65718d29..f1cb89a0b 100644
--- a/tox.ini
+++ b/tox.ini
@@ -3,16 +3,16 @@ envlist =
docs
style
packaging
- py{36,37}-dj{22,31,32}-sqlite
- py{38,39}-dj{22,31,32,main}-sqlite
- py{36,37,38,39}-dj{22,31,32}-{postgresql,mysql}
- py{310}-dj{32,main}-{sqlite,postgresql,mysql}
+ py{36,37}-dj{22,31,32}-{sqlite,postgresql,mysql}
+ py{38,39}-dj{22,31,32,40,main}-{sqlite,postgresql,mysql}
+ py{310}-dj{40,main}-{sqlite,postgresql,mysql}
[testenv]
deps =
dj22: Django==2.2.*
dj31: Django==3.1.*
- dj32: Django>=3.2a1,<4.0
+ dj32: Django>=3.2,<4.0
+ dj40: Django>=4.0a1,<4.1
sqlite: mock
postgresql: psycopg2-binary
mysql: mysqlclient
From 3b269358651ca4345b1e67265a3622f97a14a98d Mon Sep 17 00:00:00 2001
From: Tim Schilling
Date: Wed, 29 Sep 2021 15:29:59 -0500
Subject: [PATCH 08/41] Fix transifex link (net -> com)
---
docs/contributing.rst | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/docs/contributing.rst b/docs/contributing.rst
index cbb147002..b90c5a784 100644
--- a/docs/contributing.rst
+++ b/docs/contributing.rst
@@ -126,7 +126,7 @@ Translations
------------
Translation efforts are coordinated on `Transifex
-`_.
+`_.
Help translate the Debug Toolbar in your language!
From 9e13c634e85f2553cd15ee0b815fb1ce6df7fb98 Mon Sep 17 00:00:00 2001
From: Josh
Date: Sun, 10 Oct 2021 06:54:41 -0500
Subject: [PATCH 09/41] Add support for Python 3.10 (#1511)
* change to 3.10 proper in strategy matrix
* add 3.10 to trove classifers list
---
.github/workflows/test.yml | 6 +++---
setup.cfg | 1 +
2 files changed, 4 insertions(+), 3 deletions(-)
diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml
index 5ab3122fd..f0c82d4ad 100644
--- a/.github/workflows/test.yml
+++ b/.github/workflows/test.yml
@@ -9,7 +9,7 @@ jobs:
fail-fast: false
max-parallel: 5
matrix:
- python-version: ['3.6', '3.7', '3.8', '3.9', '3.10.0-rc.1']
+ python-version: ['3.6', '3.7', '3.8', '3.9', '3.10']
services:
mariadb:
@@ -76,7 +76,7 @@ jobs:
fail-fast: false
max-parallel: 5
matrix:
- python-version: ['3.6', '3.7', '3.8', '3.9', '3.10.0-rc.1']
+ python-version: ['3.6', '3.7', '3.8', '3.9', '3.10']
services:
postgres:
@@ -143,7 +143,7 @@ jobs:
fail-fast: false
max-parallel: 5
matrix:
- python-version: ['3.6', '3.7', '3.8', '3.9', '3.10.0-rc.1']
+ python-version: ['3.6', '3.7', '3.8', '3.9', '3.10']
steps:
- uses: actions/checkout@v2
diff --git a/setup.cfg b/setup.cfg
index 912fe1186..7dbfa86d4 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -27,6 +27,7 @@ classifiers =
Programming Language :: Python :: 3.7
Programming Language :: Python :: 3.8
Programming Language :: Python :: 3.9
+ Programming Language :: Python :: 3.10
Topic :: Software Development :: Libraries :: Python Modules
[options]
From 7c75eb82c041916cb830006852a2821c19e636ed Mon Sep 17 00:00:00 2001
From: "pre-commit-ci[bot]"
<66853113+pre-commit-ci[bot]@users.noreply.github.com>
Date: Mon, 11 Oct 2021 16:59:01 +0000
Subject: [PATCH 10/41] [pre-commit.ci] pre-commit autoupdate
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
updates:
- [github.com/pre-commit/pre-commit-hooks: v2.3.0 → v4.0.1](https://github.com/pre-commit/pre-commit-hooks/compare/v2.3.0...v4.0.1)
- [github.com/pycqa/flake8: 3.9.2 → 4.0.1](https://github.com/pycqa/flake8/compare/3.9.2...4.0.1)
- [github.com/pycqa/doc8: 0.9.0 → 0.9.1](https://github.com/pycqa/doc8/compare/0.9.0...0.9.1)
- [github.com/pre-commit/mirrors-prettier: v2.3.2 → v2.4.1](https://github.com/pre-commit/mirrors-prettier/compare/v2.3.2...v2.4.1)
- [github.com/pre-commit/mirrors-eslint: v8.0.0-beta.0 → v8.0.0-1](https://github.com/pre-commit/mirrors-eslint/compare/v8.0.0-beta.0...v8.0.0-1)
- [github.com/psf/black: 21.7b0 → 21.9b0](https://github.com/psf/black/compare/21.7b0...21.9b0)
---
.pre-commit-config.yaml | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
index e451190d4..a31a6144d 100644
--- a/.pre-commit-config.yaml
+++ b/.pre-commit-config.yaml
@@ -1,17 +1,17 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
- rev: v2.3.0
+ rev: v4.0.1
hooks:
- id: check-yaml
- id: end-of-file-fixer
- id: trailing-whitespace
- id: mixed-line-ending
- repo: https://github.com/pycqa/flake8
- rev: 3.9.2
+ rev: 4.0.1
hooks:
- id: flake8
- repo: https://github.com/pycqa/doc8
- rev: 0.9.0
+ rev: 0.9.1
hooks:
- id: doc8
- repo: https://github.com/pycqa/isort
@@ -28,18 +28,18 @@ repos:
- id: rst-backticks
- id: rst-directive-colons
- repo: https://github.com/pre-commit/mirrors-prettier
- rev: v2.3.2
+ rev: v2.4.1
hooks:
- id: prettier
types_or: [javascript, css]
- repo: https://github.com/pre-commit/mirrors-eslint
- rev: v8.0.0-beta.0
+ rev: v8.0.0-1
hooks:
- id: eslint
files: \.js?$
types: [file]
- repo: https://github.com/psf/black
- rev: 21.7b0
+ rev: 21.9b0
hooks:
- id: black
language_version: python3
From 8af7244ed8cdf2c94bd86eb0613c21b3c2fbf855 Mon Sep 17 00:00:00 2001
From: "pre-commit-ci[bot]"
<66853113+pre-commit-ci[bot]@users.noreply.github.com>
Date: Mon, 18 Oct 2021 16:53:20 +0000
Subject: [PATCH 11/41] [pre-commit.ci] pre-commit autoupdate
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
updates:
- [github.com/pre-commit/mirrors-eslint: v8.0.0-1 → v8.0.1](https://github.com/pre-commit/mirrors-eslint/compare/v8.0.0-1...v8.0.1)
---
.pre-commit-config.yaml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
index a31a6144d..6ccdadfe5 100644
--- a/.pre-commit-config.yaml
+++ b/.pre-commit-config.yaml
@@ -33,7 +33,7 @@ repos:
- id: prettier
types_or: [javascript, css]
- repo: https://github.com/pre-commit/mirrors-eslint
- rev: v8.0.0-1
+ rev: v8.0.1
hooks:
- id: eslint
files: \.js?$
From 7d0684c732b210b9a6488496e24f3a1c08d465de Mon Sep 17 00:00:00 2001
From: Jazzband Bot
Date: Thu, 21 Oct 2021 16:13:45 +0200
Subject: [PATCH 12/41] Jazzband: Created local 'CODE_OF_CONDUCT.md' from
remote 'CODE_OF_CONDUCT.md' (#1516)
---
CODE_OF_CONDUCT.md | 46 ++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 46 insertions(+)
create mode 100644 CODE_OF_CONDUCT.md
diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md
new file mode 100644
index 000000000..4c2fc8b5e
--- /dev/null
+++ b/CODE_OF_CONDUCT.md
@@ -0,0 +1,46 @@
+# Code of Conduct
+
+As contributors and maintainers of the Jazzband projects, and in the interest of
+fostering an open and welcoming community, we pledge to respect all people who
+contribute through reporting issues, posting feature requests, updating documentation,
+submitting pull requests or patches, and other activities.
+
+We are committed to making participation in the Jazzband a harassment-free experience
+for everyone, regardless of the level of experience, gender, gender identity and
+expression, sexual orientation, disability, personal appearance, body size, race,
+ethnicity, age, religion, or nationality.
+
+Examples of unacceptable behavior by participants include:
+
+- The use of sexualized language or imagery
+- Personal attacks
+- Trolling or insulting/derogatory comments
+- Public or private harassment
+- Publishing other's private information, such as physical or electronic addresses,
+ without explicit permission
+- Other unethical or unprofessional conduct
+
+The Jazzband roadies have the right and responsibility to remove, edit, or reject
+comments, commits, code, wiki edits, issues, and other contributions that are not
+aligned to this Code of Conduct, or to ban temporarily or permanently any contributor
+for other behaviors that they deem inappropriate, threatening, offensive, or harmful.
+
+By adopting this Code of Conduct, the roadies commit themselves to fairly and
+consistently applying these principles to every aspect of managing the jazzband
+projects. Roadies who do not follow or enforce the Code of Conduct may be permanently
+removed from the Jazzband roadies.
+
+This code of conduct applies both within project spaces and in public spaces when an
+individual is representing the project or its community.
+
+Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by
+contacting the roadies at `roadies@jazzband.co`. All complaints will be reviewed and
+investigated and will result in a response that is deemed necessary and appropriate to
+the circumstances. Roadies are obligated to maintain confidentiality with regard to the
+reporter of an incident.
+
+This Code of Conduct is adapted from the [Contributor Covenant][homepage], version
+1.3.0, available at [http://contributor-covenant.org/version/1/3/0/][version]
+
+[homepage]: http://contributor-covenant.org
+[version]: http://contributor-covenant.org/version/1/3/0/
From d1190e28b5366373022754651da8be59b852def7 Mon Sep 17 00:00:00 2001
From: jazzband-bot
Date: Thu, 21 Oct 2021 14:34:39 +0000
Subject: [PATCH 13/41] Jazzband: Synced local 'CODE_OF_CONDUCT.md' with remote
'CODE_OF_CONDUCT.md'
---
CODE_OF_CONDUCT.md | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md
index 4c2fc8b5e..e0d5efab5 100644
--- a/CODE_OF_CONDUCT.md
+++ b/CODE_OF_CONDUCT.md
@@ -40,7 +40,7 @@ the circumstances. Roadies are obligated to maintain confidentiality with regard
reporter of an incident.
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version
-1.3.0, available at [http://contributor-covenant.org/version/1/3/0/][version]
+1.3.0, available at [https://contributor-covenant.org/version/1/3/0/][version]
-[homepage]: http://contributor-covenant.org
-[version]: http://contributor-covenant.org/version/1/3/0/
+[homepage]: https://contributor-covenant.org
+[version]: https://contributor-covenant.org/version/1/3/0/
From 12248e7b145cf48d9822bcafca4288c71b48850e Mon Sep 17 00:00:00 2001
From: "pre-commit-ci[bot]"
<66853113+pre-commit-ci[bot]@users.noreply.github.com>
Date: Mon, 25 Oct 2021 16:56:58 +0000
Subject: [PATCH 14/41] [pre-commit.ci] pre-commit autoupdate
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
updates:
- [github.com/pre-commit/mirrors-eslint: v8.0.1 → v8.1.0](https://github.com/pre-commit/mirrors-eslint/compare/v8.0.1...v8.1.0)
---
.pre-commit-config.yaml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
index 6ccdadfe5..87d698263 100644
--- a/.pre-commit-config.yaml
+++ b/.pre-commit-config.yaml
@@ -33,7 +33,7 @@ repos:
- id: prettier
types_or: [javascript, css]
- repo: https://github.com/pre-commit/mirrors-eslint
- rev: v8.0.1
+ rev: v8.1.0
hooks:
- id: eslint
files: \.js?$
From 6fae2a9a5b68f06a461cb31cff5f29faf8fd646f Mon Sep 17 00:00:00 2001
From: Daniel Butler
Date: Mon, 25 Oct 2021 15:50:06 -0400
Subject: [PATCH 15/41] Additional readme warning when using docker (#1294)
* adding additional readme warning for using docker
https://gist.github.com/douglasmiranda/9de51aaba14543851ca3#file-option2-py
* Update installation.rst
fixed spelling error
Co-authored-by: sarath ak
---
docs/installation.rst | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/docs/installation.rst b/docs/installation.rst
index 27a6b6b85..e68ee593e 100644
--- a/docs/installation.rst
+++ b/docs/installation.rst
@@ -103,6 +103,17 @@ You can change the logic of determining whether or not the Debug Toolbar
should be shown with the :ref:`SHOW_TOOLBAR_CALLBACK `
option. This option allows you to specify a custom function for this purpose.
+.. warning::
+
+ If using Docker the following will set your `INTERNAL_IPS` correctly only if you are in Debug mode.::
+
+ if DEBUG:
+ import os # only if you haven't already imported this
+ import socket # only if you haven't already imported this
+ hostname, _, ips = socker.gethostbyname_ex(socket.gethostname())
+ INTERNAL_IPS = [ip[:-1] + '1' for ip in ips] + ['127.0.0.1', '10.0.2.2']
+
+
Troubleshooting
---------------
From 1e873bcbbadd45f950521e7ff4f1057187aaa3d7 Mon Sep 17 00:00:00 2001
From: Jan Pieter Waagmeester
Date: Tue, 22 Dec 2020 09:41:21 +0100
Subject: [PATCH 16/41] Fix SQL selected / SQL explain for gis queries
Without this fix, pushing the 'sel' or 'explain' button for a query containing some EWKB-encoded geometry
as parameter results in this crash:
```
Internal Server Error: /__debug__/sql_explain/
Traceback (most recent call last):
File "/Users/jieter/.pyenv/versions/obs/lib/python3.8/site-packages/django/db/backends/utils.py", line 86, in _execute
return self.cursor.execute(sql, params)
psycopg2.errors.InternalError_: parse error - invalid geometry
LINE 1: ...ure" IN (0, 1, 5)) AND "waarneming"."geo_point" @ 'ST_GeomFr...
^
HINT: "ST" <-- parse error at position 2 within geometry
```
I'm not sure if this is the appropriate location in the code, but with this fix, both `sql_select` and `sql_explain`
work without flaws.
Previous PR adding a similar fix: #1130
Fixes: #423
---
debug_toolbar/panels/sql/tracking.py | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/debug_toolbar/panels/sql/tracking.py b/debug_toolbar/panels/sql/tracking.py
index 2ed691344..7090ac613 100644
--- a/debug_toolbar/panels/sql/tracking.py
+++ b/debug_toolbar/panels/sql/tracking.py
@@ -137,6 +137,14 @@ def _decode(self, param):
def _record(self, method, sql, params):
start_time = time()
try:
+ if isinstance(params, list):
+
+ def strip_GeomFromEWKB(param):
+ if isinstance(param, str):
+ return param.lstrip("ST_GeomFromEWKB('\\x").rstrip("'::bytea)")
+ return param
+
+ params = [strip_GeomFromEWKB(param) for param in params]
return method(sql, params)
finally:
stop_time = time()
From 632e02cd464230e5095cba45b5fcef32a6d91321 Mon Sep 17 00:00:00 2001
From: Jan Pieter Waagmeester
Date: Wed, 23 Dec 2020 13:56:00 +0100
Subject: [PATCH 17/41] Add Postgis to tests, attemt to add regression test
---
tests/models.py | 8 ++++++++
tests/panels/test_staticfiles.py | 14 ++++++++------
tests/settings.py | 9 ++++++++-
tests/test_integration.py | 24 ++++++++++++++++++++++++
tox.ini | 8 +++++---
5 files changed, 53 insertions(+), 10 deletions(-)
diff --git a/tests/models.py b/tests/models.py
index d6829eabc..0c070a7f2 100644
--- a/tests/models.py
+++ b/tests/models.py
@@ -1,3 +1,4 @@
+from django.conf import settings
from django.db import models
@@ -23,3 +24,10 @@ class Binary(models.Model):
class PostgresJSON(models.Model):
field = JSONField()
+
+
+if settings.USE_GIS:
+ from django.contrib.gis.db import models as gismodels
+
+ class Location(gismodels.Model):
+ point = gismodels.PointField()
diff --git a/tests/panels/test_staticfiles.py b/tests/panels/test_staticfiles.py
index d660b3c77..32ed7ea61 100644
--- a/tests/panels/test_staticfiles.py
+++ b/tests/panels/test_staticfiles.py
@@ -26,9 +26,10 @@ def test_default_case(self):
)
self.assertEqual(self.panel.num_used, 0)
self.assertNotEqual(self.panel.num_found, 0)
- self.assertEqual(
- self.panel.get_staticfiles_apps(), ["django.contrib.admin", "debug_toolbar"]
- )
+ expected_apps = ["django.contrib.admin", "debug_toolbar"]
+ if settings.USE_GIS:
+ expected_apps = ["django.contrib.gis"] + expected_apps
+ self.assertEqual(self.panel.get_staticfiles_apps(), expected_apps)
self.assertEqual(
self.panel.get_staticfiles_dirs(), finders.FileSystemFinder().locations
)
@@ -74,9 +75,10 @@ def test_finder_directory_does_not_exist(self):
)
self.assertEqual(self.panel.num_used, 0)
self.assertNotEqual(self.panel.num_found, 0)
- self.assertEqual(
- self.panel.get_staticfiles_apps(), ["django.contrib.admin", "debug_toolbar"]
- )
+ expected_apps = ["django.contrib.admin", "debug_toolbar"]
+ if settings.USE_GIS:
+ expected_apps = ["django.contrib.gis"] + expected_apps
+ self.assertEqual(self.panel.get_staticfiles_apps(), expected_apps)
self.assertEqual(
self.panel.get_staticfiles_dirs(), finders.FileSystemFinder().locations
)
diff --git a/tests/settings.py b/tests/settings.py
index 2a4b5e68c..63456a2f6 100644
--- a/tests/settings.py
+++ b/tests/settings.py
@@ -27,6 +27,11 @@
"tests",
]
+USE_GIS = os.getenv("DB_BACKEND") in ("postgis",)
+
+if USE_GIS:
+ INSTALLED_APPS = ["django.contrib.gis"] + INSTALLED_APPS
+
MEDIA_URL = "/media/" # Avoids https://code.djangoproject.com/ticket/21451
MIDDLEWARE = [
@@ -82,7 +87,9 @@
DATABASES = {
"default": {
- "ENGINE": "django.db.backends.%s" % os.getenv("DB_BACKEND", "sqlite3"),
+ "ENGINE": "django.{}db.backends.{}".format(
+ "contrib.gis." if USE_GIS else "", os.getenv("DB_BACKEND", "sqlite3")
+ ),
"NAME": os.getenv("DB_NAME", ":memory:"),
"USER": os.getenv("DB_USER"),
"PASSWORD": os.getenv("DB_PASSWORD"),
diff --git a/tests/test_integration.py b/tests/test_integration.py
index 3be1ef589..23b12eef6 100644
--- a/tests/test_integration.py
+++ b/tests/test_integration.py
@@ -1,9 +1,11 @@
+import json
import os
import re
import unittest
import django
import html5lib
+from django.conf import settings
from django.contrib.staticfiles.testing import StaticLiveServerTestCase
from django.core import signing
from django.core.cache import cache
@@ -16,6 +18,7 @@
from debug_toolbar.forms import SignedDataForm
from debug_toolbar.middleware import DebugToolbarMiddleware, show_toolbar
from debug_toolbar.panels import Panel
+from debug_toolbar.panels.sql.forms import SQLSelectForm
from debug_toolbar.toolbar import DebugToolbar
from .base import BaseTestCase, IntegrationTestCase
@@ -293,6 +296,27 @@ def test_sql_explain_checks_show_toolbar(self):
)
self.assertEqual(response.status_code, 404)
+ @unittest.skipUnless(settings.USE_GIS, "Test only valid with gis support")
+ def test_sql_explain_gis(self):
+ from django.contrib.gis.geos import GEOSGeometry
+ from .models import Location
+
+ db_table = Location._meta.db_table
+
+ url = "/__debug__/sql_explain/"
+ geom = GEOSGeometry("POLYGON((0 0, 0 1, 1 1, 0 0))")
+ data = {
+ "sql": f'SELECT "{db_table}"."point" FROM "{db_table}" WHERE "{db_table}"."point" @ {geom.hex} LIMIT 1',
+ "raw_sql": f'SELECT "{db_table}"."point" FROM "{db_table}" WHERE "{db_table}"."point" @ %s LIMIT 1',
+ "params": json.dumps([geom.hex]),
+ "alias": "default",
+ "duration": "0",
+ }
+ data["hash"] = SQLSelectForm().make_hash(data)
+
+ response = self.client.post(url, data=data)
+ self.assertEqual(response.status_code, 200)
+
@unittest.skipUnless(
connection.vendor == "postgresql", "Test valid only on PostgreSQL"
)
diff --git a/tox.ini b/tox.ini
index f1cb89a0b..0cd67796b 100644
--- a/tox.ini
+++ b/tox.ini
@@ -3,9 +3,9 @@ envlist =
docs
style
packaging
- py{36,37}-dj{22,31,32}-{sqlite,postgresql,mysql}
- py{38,39}-dj{22,31,32,40,main}-{sqlite,postgresql,mysql}
- py{310}-dj{40,main}-{sqlite,postgresql,mysql}
+ py{36,37}-dj{22,31,32}-{sqlite,postgresql,postgis,mysql}
+ py{38,39}-dj{22,31,32,40,main}-{sqlite,postgresql,postgis,mysql}
+ py{310}-dj{40,main}-{sqlite,postgresql,postgis,mysql}
[testenv]
deps =
@@ -15,6 +15,7 @@ deps =
dj40: Django>=4.0a1,<4.1
sqlite: mock
postgresql: psycopg2-binary
+ postgis: psycopg2-binary
mysql: mysqlclient
djmain: https://github.com/django/django/archive/main.tar.gz
coverage
@@ -97,4 +98,5 @@ python =
DB_BACKEND =
mysql: mysql
postgresql: postgresql
+ postgis: postgresql
sqlite3: sqlite
From 857993c1fb7e47728954e057ac4ea0333e72c851 Mon Sep 17 00:00:00 2001
From: "pre-commit-ci[bot]"
<66853113+pre-commit-ci[bot]@users.noreply.github.com>
Date: Tue, 26 Oct 2021 06:13:35 +0000
Subject: [PATCH 18/41] [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
---
docs/installation.rst | 6 +++---
tests/test_integration.py | 1 +
2 files changed, 4 insertions(+), 3 deletions(-)
diff --git a/docs/installation.rst b/docs/installation.rst
index e68ee593e..723c8f595 100644
--- a/docs/installation.rst
+++ b/docs/installation.rst
@@ -106,14 +106,14 @@ option. This option allows you to specify a custom function for this purpose.
.. warning::
If using Docker the following will set your `INTERNAL_IPS` correctly only if you are in Debug mode.::
-
+
if DEBUG:
import os # only if you haven't already imported this
import socket # only if you haven't already imported this
hostname, _, ips = socker.gethostbyname_ex(socket.gethostname())
INTERNAL_IPS = [ip[:-1] + '1' for ip in ips] + ['127.0.0.1', '10.0.2.2']
-
-
+
+
Troubleshooting
---------------
diff --git a/tests/test_integration.py b/tests/test_integration.py
index 23b12eef6..bfee12a9f 100644
--- a/tests/test_integration.py
+++ b/tests/test_integration.py
@@ -299,6 +299,7 @@ def test_sql_explain_checks_show_toolbar(self):
@unittest.skipUnless(settings.USE_GIS, "Test only valid with gis support")
def test_sql_explain_gis(self):
from django.contrib.gis.geos import GEOSGeometry
+
from .models import Location
db_table = Location._meta.db_table
From 8633926d3d98bbd738474598652cc4b808490583 Mon Sep 17 00:00:00 2001
From: Noam
Date: Thu, 9 Jul 2020 12:57:44 +0300
Subject: [PATCH 19/41] Allowed using ProfilingPanel as non last panel.
---
debug_toolbar/panels/profiling.py | 35 ++++---------------------------
1 file changed, 4 insertions(+), 31 deletions(-)
diff --git a/debug_toolbar/panels/profiling.py b/debug_toolbar/panels/profiling.py
index fdd5ed06e..3acd5fabe 100644
--- a/debug_toolbar/panels/profiling.py
+++ b/debug_toolbar/panels/profiling.py
@@ -9,33 +9,6 @@
from debug_toolbar import settings as dt_settings
from debug_toolbar.panels import Panel
-# Occasionally the disable method on the profiler is listed before
-# the actual view functions. This function call should be ignored as
-# it leads to an error within the tests.
-INVALID_PROFILER_FUNC = "_lsprof.Profiler"
-
-
-def contains_profiler(func_tuple):
- """Helper function that checks to see if the tuple contains
- the INVALID_PROFILE_FUNC in any string value of the tuple."""
- has_profiler = False
- for value in func_tuple:
- if isinstance(value, str):
- has_profiler |= INVALID_PROFILER_FUNC in value
- return has_profiler
-
-
-class DjangoDebugToolbarStats(Stats):
- __root = None
-
- def get_root_func(self):
- if self.__root is None:
- for func, (cc, nc, tt, ct, callers) in self.stats.items():
- if len(callers) == 0 and not contains_profiler(func):
- self.__root = func
- break
- return self.__root
-
class FunctionCall:
def __init__(
@@ -169,12 +142,12 @@ def generate_stats(self, request, response):
return None
# Could be delayed until the panel content is requested (perf. optim.)
self.profiler.create_stats()
- self.stats = DjangoDebugToolbarStats(self.profiler)
+ self.stats = Stats(self.profiler)
self.stats.calc_callees()
- root_func = self.stats.get_root_func()
- # Ensure root function exists before continuing with function call analysis
- if root_func:
+ root_func = cProfile.label(super().process_request.__code__)
+
+ if root_func in self.stats.stats:
root = FunctionCall(self.stats, root_func, depth=0)
func_list = []
self.add_node(
From f899efbbd28a067a328ed46d36eb416de298233d Mon Sep 17 00:00:00 2001
From: Asif Saif Uddin
Date: Tue, 26 Oct 2021 13:21:08 +0600
Subject: [PATCH 20/41] Update tox.ini
---
tox.ini | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tox.ini b/tox.ini
index 0cd67796b..208227e33 100644
--- a/tox.ini
+++ b/tox.ini
@@ -12,7 +12,7 @@ deps =
dj22: Django==2.2.*
dj31: Django==3.1.*
dj32: Django>=3.2,<4.0
- dj40: Django>=4.0a1,<4.1
+ dj40: Django>=4.0b1,<4.1
sqlite: mock
postgresql: psycopg2-binary
postgis: psycopg2-binary
From 703ab67d0a1c927d2253622e6c62d56bf4bf39e0 Mon Sep 17 00:00:00 2001
From: mahbd <53579616+mahbd@users.noreply.github.com>
Date: Wed, 27 Oct 2021 06:55:57 +0600
Subject: [PATCH 21/41] Solve spelling mistake.
There was a spelling mistake on line 113. "socker" should be "socket".
---
docs/installation.rst | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/docs/installation.rst b/docs/installation.rst
index 723c8f595..ed3dfd0cb 100644
--- a/docs/installation.rst
+++ b/docs/installation.rst
@@ -110,7 +110,7 @@ option. This option allows you to specify a custom function for this purpose.
if DEBUG:
import os # only if you haven't already imported this
import socket # only if you haven't already imported this
- hostname, _, ips = socker.gethostbyname_ex(socket.gethostname())
+ hostname, _, ips = socket.gethostbyname_ex(socket.gethostname())
INTERNAL_IPS = [ip[:-1] + '1' for ip in ips] + ['127.0.0.1', '10.0.2.2']
From 50b19817726152ff9265d8a386d494f1d48d9274 Mon Sep 17 00:00:00 2001
From: Hasan Ramezani
Date: Mon, 1 Nov 2021 18:52:10 +0330
Subject: [PATCH 22/41] Add Python 3.10 test pipeline for Django 3.2 (#1521)
---
tox.ini | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tox.ini b/tox.ini
index 208227e33..c72cbb546 100644
--- a/tox.ini
+++ b/tox.ini
@@ -5,7 +5,7 @@ envlist =
packaging
py{36,37}-dj{22,31,32}-{sqlite,postgresql,postgis,mysql}
py{38,39}-dj{22,31,32,40,main}-{sqlite,postgresql,postgis,mysql}
- py{310}-dj{40,main}-{sqlite,postgresql,postgis,mysql}
+ py{310}-dj{32,40,main}-{sqlite,postgresql,postgis,mysql}
[testenv]
deps =
From e139c6ff590527b45a97099db672c710cca975d1 Mon Sep 17 00:00:00 2001
From: "pre-commit-ci[bot]"
<66853113+pre-commit-ci[bot]@users.noreply.github.com>
Date: Mon, 1 Nov 2021 18:37:38 +0100
Subject: [PATCH 23/41] [pre-commit.ci] pre-commit autoupdate (#1522)
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
updates:
- [github.com/psf/black: 21.9b0 → 21.10b0](https://github.com/psf/black/compare/21.9b0...21.10b0)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
---
.pre-commit-config.yaml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
index 87d698263..561781da9 100644
--- a/.pre-commit-config.yaml
+++ b/.pre-commit-config.yaml
@@ -39,7 +39,7 @@ repos:
files: \.js?$
types: [file]
- repo: https://github.com/psf/black
- rev: 21.9b0
+ rev: 21.10b0
hooks:
- id: black
language_version: python3
From e4b452909f30f598e952dcb9f7fecfe487dc139a Mon Sep 17 00:00:00 2001
From: Tim Schilling
Date: Thu, 4 Nov 2021 16:25:38 -0500
Subject: [PATCH 24/41] Run CI tests weekly.
This helps identify issues with the library as
django and other dependencies release new versions.
---
.github/workflows/test.yml | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml
index f0c82d4ad..7d4cf45f8 100644
--- a/.github/workflows/test.yml
+++ b/.github/workflows/test.yml
@@ -1,6 +1,11 @@
name: Test
-on: [push, pull_request]
+on:
+ push:
+ pull_request:
+ schedule:
+ # Run weekly on Saturday
+ - cron: '37 3 * * SAT'
jobs:
mysql:
From a76aeadd6fa2835dd4ccc19f7c02e1ea354e6c81 Mon Sep 17 00:00:00 2001
From: Tim Schilling
Date: Fri, 5 Nov 2021 17:04:09 -0500
Subject: [PATCH 25/41] Fix test_param_conversion for Django 4.1 and mysql
---
tests/panels/test_sql.py | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/tests/panels/test_sql.py b/tests/panels/test_sql.py
index 6ca241f41..9358a2f70 100644
--- a/tests/panels/test_sql.py
+++ b/tests/panels/test_sql.py
@@ -138,7 +138,12 @@ def test_param_conversion(self):
# ensure query was logged
self.assertEqual(len(self.panel._queries), 3)
- if django.VERSION >= (3, 1):
+ if (
+ django.VERSION >= (3, 1)
+ # Django 4.1 started passing true/false back for boolean
+ # comparisons in MySQL.
+ and not (django.VERSION >= (4, 1) and connection.vendor == "mysql")
+ ):
self.assertEqual(
tuple([q[1]["params"] for q in self.panel._queries]),
('["Foo"]', "[10, 1]", '["2017-12-22 16:07:01"]'),
From d0300b17f31fc7c9ca93190f23007d994610d625 Mon Sep 17 00:00:00 2001
From: "pre-commit-ci[bot]"
<66853113+pre-commit-ci[bot]@users.noreply.github.com>
Date: Mon, 8 Nov 2021 17:05:30 +0000
Subject: [PATCH 26/41] [pre-commit.ci] pre-commit autoupdate
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
updates:
- [github.com/pycqa/isort: 5.9.3 → 5.10.0](https://github.com/pycqa/isort/compare/5.9.3...5.10.0)
- [github.com/pre-commit/mirrors-eslint: v8.1.0 → v8.2.0](https://github.com/pre-commit/mirrors-eslint/compare/v8.1.0...v8.2.0)
---
.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 561781da9..99d4f7da0 100644
--- a/.pre-commit-config.yaml
+++ b/.pre-commit-config.yaml
@@ -15,7 +15,7 @@ repos:
hooks:
- id: doc8
- repo: https://github.com/pycqa/isort
- rev: 5.9.3
+ rev: 5.10.0
hooks:
- id: isort
- repo: https://github.com/pre-commit/pygrep-hooks
@@ -33,7 +33,7 @@ repos:
- id: prettier
types_or: [javascript, css]
- repo: https://github.com/pre-commit/mirrors-eslint
- rev: v8.1.0
+ rev: v8.2.0
hooks:
- id: eslint
files: \.js?$
From 3bdd40cdd5a399b9fe1f1970640454820397135b Mon Sep 17 00:00:00 2001
From: Adam Johnson
Date: Mon, 15 Nov 2021 17:17:26 +0000
Subject: [PATCH 27/41] Remove settings import from install instructions.
(#1528)
The import of settings is no longer required after #1349
---
docs/installation.rst | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/docs/installation.rst b/docs/installation.rst
index ed3dfd0cb..58bbaf609 100644
--- a/docs/installation.rst
+++ b/docs/installation.rst
@@ -51,11 +51,10 @@ Setting up URLconf
Add the Debug Toolbar's URLs to your project's URLconf::
import debug_toolbar
- from django.conf import settings
from django.urls import include, path
urlpatterns = [
- ...
+ # ...
path('__debug__/', include(debug_toolbar.urls)),
]
From 1724c4ba9aa0155e3a381d11585177b5f931faac Mon Sep 17 00:00:00 2001
From: Matthias Kestenholz
Date: Mon, 15 Nov 2021 20:37:20 +0100
Subject: [PATCH 28/41] Add a big warning regarding the security implications
of changing SHOW_TOOLBAR_CALLBACK (#1530)
---
docs/configuration.rst | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/docs/configuration.rst b/docs/configuration.rst
index 96758d89c..7219c8167 100644
--- a/docs/configuration.rst
+++ b/docs/configuration.rst
@@ -123,6 +123,12 @@ Toolbar options
the callback. This allows reusing the callback to verify access to panel
views requested via AJAX.
+ .. warning::
+
+ Please note that the debug toolbar isn't hardened for use in production
+ environments or on public servers. You should be aware of the implications
+ to the security of your servers when using your own callback.
+
Panel options
~~~~~~~~~~~~~
From f5454d7501e11d00346973e6efeed38903c6d22e Mon Sep 17 00:00:00 2001
From: "pre-commit-ci[bot]"
<66853113+pre-commit-ci[bot]@users.noreply.github.com>
Date: Mon, 15 Nov 2021 17:07:09 +0000
Subject: [PATCH 29/41] [pre-commit.ci] pre-commit autoupdate
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
updates:
- [github.com/pycqa/doc8: 0.9.1 → 0.10.1](https://github.com/pycqa/doc8/compare/0.9.1...0.10.1)
- [github.com/pycqa/isort: 5.10.0 → 5.10.1](https://github.com/pycqa/isort/compare/5.10.0...5.10.1)
---
.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 99d4f7da0..77f8af6ad 100644
--- a/.pre-commit-config.yaml
+++ b/.pre-commit-config.yaml
@@ -11,11 +11,11 @@ repos:
hooks:
- id: flake8
- repo: https://github.com/pycqa/doc8
- rev: 0.9.1
+ rev: 0.10.1
hooks:
- id: doc8
- repo: https://github.com/pycqa/isort
- rev: 5.10.0
+ rev: 5.10.1
hooks:
- id: isort
- repo: https://github.com/pre-commit/pygrep-hooks
From f74eabc8474eb294d979a1f2b79d2f0d826c4eff Mon Sep 17 00:00:00 2001
From: Paolo Melchiorre
Date: Mon, 22 Nov 2021 12:03:05 +0100
Subject: [PATCH 30/41] Update Django 4.0 version in tox.ini to RC1 (#1531)
---
tox.ini | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tox.ini b/tox.ini
index c72cbb546..3a5d428e5 100644
--- a/tox.ini
+++ b/tox.ini
@@ -12,7 +12,7 @@ deps =
dj22: Django==2.2.*
dj31: Django==3.1.*
dj32: Django>=3.2,<4.0
- dj40: Django>=4.0b1,<4.1
+ dj40: Django>=4.0rc1,<4.1
sqlite: mock
postgresql: psycopg2-binary
postgis: psycopg2-binary
From ea743e057f31404003b694729431021dad311df5 Mon Sep 17 00:00:00 2001
From: "pre-commit-ci[bot]"
<66853113+pre-commit-ci[bot]@users.noreply.github.com>
Date: Mon, 22 Nov 2021 21:00:39 +0100
Subject: [PATCH 31/41] [pre-commit.ci] pre-commit autoupdate (#1532)
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
updates:
- [github.com/pre-commit/mirrors-eslint: v8.2.0 → v8.3.0](https://github.com/pre-commit/mirrors-eslint/compare/v8.2.0...v8.3.0)
- [github.com/psf/black: 21.10b0 → 21.11b1](https://github.com/psf/black/compare/21.10b0...21.11b1)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
---
.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 77f8af6ad..6ce264484 100644
--- a/.pre-commit-config.yaml
+++ b/.pre-commit-config.yaml
@@ -33,13 +33,13 @@ repos:
- id: prettier
types_or: [javascript, css]
- repo: https://github.com/pre-commit/mirrors-eslint
- rev: v8.2.0
+ rev: v8.3.0
hooks:
- id: eslint
files: \.js?$
types: [file]
- repo: https://github.com/psf/black
- rev: 21.10b0
+ rev: 21.11b1
hooks:
- id: black
language_version: python3
From fe0db68a8caf8aca0935f1efcc4ce28f9272b4dc Mon Sep 17 00:00:00 2001
From: Adam Johnson
Date: Tue, 23 Nov 2021 10:43:10 +0000
Subject: [PATCH 32/41] Improve installation instructions (#1533)
* Number the steps
* Separate installation steps from troubleshooting section
* Use imperative tone ("Adding the URLs" -> "Add the URLs")
* Split prerequisites from adding app
* Show example of minimal required template backend
* Convert code to black style (double quoted strings)
* Simplify wording in several places.
---
docs/installation.rst | 98 ++++++++++++++++++++++++++++---------------
1 file changed, 65 insertions(+), 33 deletions(-)
diff --git a/docs/installation.rst b/docs/installation.rst
index 58bbaf609..354213341 100644
--- a/docs/installation.rst
+++ b/docs/installation.rst
@@ -1,11 +1,14 @@
Installation
============
+Process
+-------
+
Each of the following steps needs to be configured for the Debug Toolbar to be
fully functional.
-Getting the code
-----------------
+1. Install the Package
+^^^^^^^^^^^^^^^^^^^^^^
The recommended way to install the Debug Toolbar is via pip_::
@@ -21,34 +24,60 @@ instead with the following command::
$ python -m pip install -e git+https://github.com/jazzband/django-debug-toolbar.git#egg=django-debug-toolbar
-Prerequisites
--------------
+If you're upgrading from a previous version, you should review the
+:doc:`change log ` and look for specific upgrade instructions.
+
+2. Check for Prerequisites
+^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+The Debug Toolbar requires two things from core Django. These are already
+configured in Django’s default ``startproject`` template, so in most cases you
+will already have these set up.
-Make sure that ``'django.contrib.staticfiles'`` is `set up properly
-`_ and add
-``'debug_toolbar'`` to your ``INSTALLED_APPS`` setting::
+First, ensure that ``'django.contrib.staticfiles'`` is in your
+``INSTALLED_APPS`` setting, and `configured properly
+`_:
+
+.. code-block:: python
INSTALLED_APPS = [
# ...
- 'django.contrib.staticfiles',
+ "django.contrib.staticfiles",
# ...
- 'debug_toolbar',
]
- STATIC_URL = '/static/'
+ STATIC_URL = "static/"
-Make sure your ``TEMPLATES`` setting contains a ``DjangoTemplates`` backend
-whose ``APP_DIRS`` options is set to ``True``. It's in there by default, so
-you'll only need to change this if you've changed that setting.
+Second, ensure that your ``TEMPLATES`` setting contains a
+``DjangoTemplates`` backend whose ``APP_DIRS`` options is set to ``True``:
+.. code-block:: python
-If you're upgrading from a previous version, you should review the
-:doc:`change log ` and look for specific upgrade instructions.
+ TEMPLATES = [
+ {
+ "BACKEND": "django.template.backends.django.DjangoTemplates",
+ "APP_DIRS": True,
+ # ...
+ }
+ ]
+
+3. Install the App
+^^^^^^^^^^^^^^^^^^
-Setting up URLconf
-------------------
+Add ``"debug_toolbar"`` to your ``INSTALLED_APPS`` setting::
-Add the Debug Toolbar's URLs to your project's URLconf::
+ INSTALLED_APPS = [
+ # ...
+ "debug_toolbar",
+ # ...
+ ]
+
+4. Add the URLs
+^^^^^^^^^^^^^^^
+
+Add django-debug-toolbar's URLs to your project's URLconf:
+
+.. code-block:: python
import debug_toolbar
from django.urls import include, path
@@ -62,15 +91,17 @@ This example uses the ``__debug__`` prefix, but you can use any prefix that
doesn't clash with your application's URLs. Note the lack of quotes around
``debug_toolbar.urls``.
-Enabling middleware
--------------------
+5. Add the Middleware
+^^^^^^^^^^^^^^^^^^^^^
+
+The Debug Toolbar is mostly implemented in a middleware. Add it to your
+``MIDDLEWARE`` setting:
-The Debug Toolbar is mostly implemented in a middleware. Enable it in your
-settings module as follows::
+.. code-block:: python
MIDDLEWARE = [
# ...
- 'debug_toolbar.middleware.DebugToolbarMiddleware',
+ "debug_toolbar.middleware.DebugToolbarMiddleware",
# ...
]
@@ -83,28 +114,30 @@ settings module as follows::
.. _internal-ips:
-Configuring Internal IPs
-------------------------
+6. Configure Internal IPs
+^^^^^^^^^^^^^^^^^^^^^^^^^
-The Debug Toolbar is shown only if your IP address is listed in the
+The Debug Toolbar is shown only if your IP address is listed in Django’s
:setting:`INTERNAL_IPS` setting. This means that for local
-development, you *must* add ``'127.0.0.1'`` to :setting:`INTERNAL_IPS`;
-you'll need to create this setting if it doesn't already exist in your
-settings module::
+development, you *must* add ``"127.0.0.1"`` to :setting:`INTERNAL_IPS`.
+You'll need to create this setting if it doesn't already exist in your
+settings module:
+
+.. code-block:: python
INTERNAL_IPS = [
# ...
- '127.0.0.1',
+ "127.0.0.1",
# ...
]
You can change the logic of determining whether or not the Debug Toolbar
should be shown with the :ref:`SHOW_TOOLBAR_CALLBACK `
-option. This option allows you to specify a custom function for this purpose.
+option.
.. warning::
- If using Docker the following will set your `INTERNAL_IPS` correctly only if you are in Debug mode.::
+ If using Docker the following will set your ``INTERNAL_IPS`` correctly in Debug mode::
if DEBUG:
import os # only if you haven't already imported this
@@ -112,7 +145,6 @@ option. This option allows you to specify a custom function for this purpose.
hostname, _, ips = socket.gethostbyname_ex(socket.gethostname())
INTERNAL_IPS = [ip[:-1] + '1' for ip in ips] + ['127.0.0.1', '10.0.2.2']
-
Troubleshooting
---------------
From 250d3fe4ad20f531d4bae9c4c4bbe8cf47357851 Mon Sep 17 00:00:00 2001
From: Adam Johnson
Date: Wed, 24 Nov 2021 11:07:44 +0000
Subject: [PATCH 33/41] Fix settings docs (#1534)
* Fix settings docs
* Remove comment in ``debug_toolbar/settings.py`` that was invalidated in a8fa2cf467d8a8234b16e4bb9f45fbaa60597392.
* Fix documented default for ``DISABLE_PANELS``.
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
---
debug_toolbar/settings.py | 7 -------
docs/configuration.rst | 9 ++++++++-
2 files changed, 8 insertions(+), 8 deletions(-)
diff --git a/debug_toolbar/settings.py b/debug_toolbar/settings.py
index d8e6868a3..d512e11ae 100644
--- a/debug_toolbar/settings.py
+++ b/debug_toolbar/settings.py
@@ -2,13 +2,6 @@
from django.conf import settings
-# Always import this module as follows:
-# from debug_toolbar import settings [as dt_settings]
-
-# Don't import directly CONFIG or PANELs, or you will miss changes performed
-# with override_settings in tests.
-
-
CONFIG_DEFAULTS = {
# Toolbar options
"DISABLE_PANELS": {
diff --git a/docs/configuration.rst b/docs/configuration.rst
index 7219c8167..084480dde 100644
--- a/docs/configuration.rst
+++ b/docs/configuration.rst
@@ -54,7 +54,14 @@ Toolbar options
* ``DISABLE_PANELS``
- Default: ``{'debug_toolbar.panels.redirects.RedirectsPanel'}``
+ Default:
+
+ .. code-block:: python
+
+ {
+ "debug_toolbar.panels.profiling.ProfilingPanel",
+ "debug_toolbar.panels.redirects.RedirectsPanel",
+ }
This setting is a set of the full Python paths to each panel that you
want disabled (but still displayed) by default.
From 5665d6808ce0780d2594157684dd6869d1e048a5 Mon Sep 17 00:00:00 2001
From: Adam Johnson
Date: Wed, 24 Nov 2021 12:59:58 +0000
Subject: [PATCH 34/41] Use only pre-commit for style linters and fixers
(#1535)
* Use only pre-commit for style linters and fixers
The method of using the `Makefile`, running under `tox`, duplicated the work of pre-commit and pre-commit.ci. Additionally tox did not use the same pinned versions and arguments as in `.pre-commit-config.yaml`, so there is the potential for a version clash to cause the two paths to conflict, e.g. when a new version of Black is released.
Sticking to only `pre-commit` seems sensible, saves some CI time, and allows some files to be removed.
* spelling
---
.github/workflows/test.yml | 2 +-
.gitignore | 2 --
.pre-commit-config.yaml | 2 ++
Makefile | 24 +-----------------------
docs/contributing.rst | 9 +++++++--
docs/spelling_wordlist.txt | 1 +
package.json | 6 ------
tox.ini | 9 ---------
8 files changed, 12 insertions(+), 43 deletions(-)
delete mode 100644 package.json
diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml
index 7d4cf45f8..050d5b11d 100644
--- a/.github/workflows/test.yml
+++ b/.github/workflows/test.yml
@@ -221,4 +221,4 @@ jobs:
python -m pip install --upgrade tox
- name: Test with tox
- run: tox -e docs,style,packaging
+ run: tox -e docs,packaging
diff --git a/.gitignore b/.gitignore
index df5a2d10c..6caa61357 100644
--- a/.gitignore
+++ b/.gitignore
@@ -10,7 +10,5 @@ docs/_build
example/db.sqlite3
htmlcov
.tox
-node_modules
-package-lock.json
geckodriver.log
coverage.xml
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
index 6ce264484..7e6cd3f8b 100644
--- a/.pre-commit-config.yaml
+++ b/.pre-commit-config.yaml
@@ -38,6 +38,8 @@ repos:
- id: eslint
files: \.js?$
types: [file]
+ args:
+ - --fix
- repo: https://github.com/psf/black
rev: 21.11b1
hooks:
diff --git a/Makefile b/Makefile
index 5b5ca4d76..1600496e5 100644
--- a/Makefile
+++ b/Makefile
@@ -1,22 +1,4 @@
-.PHONY: flake8 example test coverage translatable_strings update_translations
-
-PRETTIER_TARGETS = '**/*.(css|js)'
-
-style: package-lock.json
- isort .
- black --target-version=py36 .
- flake8
- npx eslint --ignore-path .gitignore --fix .
- npx prettier --ignore-path .gitignore --write $(PRETTIER_TARGETS)
- ! grep -r '\(style=\|onclick=\|\|