Skip to content

Commit 8acfbe5

Browse files
committed
Drop support for Django 2.2.
1 parent 1964826 commit 8acfbe5

File tree

13 files changed

+46
-127
lines changed

13 files changed

+46
-127
lines changed

README.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ In addition to the built-in panels, a number of third-party panels are
4545
contributed by the community.
4646

4747
The current stable version of the Debug Toolbar is 3.2.4. It works on
48-
Django ≥ 2.2.
48+
Django ≥ 3.2.
4949

5050
Documentation, including installation and configuration instructions, is
5151
available at https://django-debug-toolbar.readthedocs.io/.

debug_toolbar/__init__.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import django
2-
31
from debug_toolbar.urls import app_name
42

53
__all__ = ["VERSION"]
@@ -12,6 +10,3 @@
1210
# Code that discovers files or modules in INSTALLED_APPS imports this module.
1311

1412
urls = "debug_toolbar.urls", app_name
15-
16-
if django.VERSION < (3, 2):
17-
default_app_config = "debug_toolbar.apps.DebugToolbarConfig"

debug_toolbar/management/commands/debugsqlshell.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
from time import time
22

3-
import django
43
import sqlparse
54
from django.core.management.commands.shell import Command
65
from django.db import connection
76

8-
if connection.vendor == "postgresql" and django.VERSION >= (3, 0, 0):
7+
if connection.vendor == "postgresql":
98
from django.db.backends.postgresql import base as base_module
109
else:
1110
from django.db.backends import utils as base_module

debug_toolbar/panels/cache.py

Lines changed: 23 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,9 @@
88
except ImportError:
99
ConnectionProxy = None
1010

11-
import django
1211
from django.conf import settings
1312
from django.core import cache
14-
from django.core.cache import (
15-
DEFAULT_CACHE_ALIAS,
16-
CacheHandler,
17-
cache as original_cache,
18-
caches as original_caches,
19-
)
13+
from django.core.cache import DEFAULT_CACHE_ALIAS, CacheHandler
2014
from django.core.cache.backends.base import BaseCache
2115
from django.dispatch import Signal
2216
from django.middleware import cache as middleware_cache
@@ -141,26 +135,17 @@ def decr_version(self, *args, **kwargs):
141135
return self.cache.decr_version(*args, **kwargs)
142136

143137

144-
if django.VERSION < (3, 2):
138+
class CacheHandlerPatch(CacheHandler):
139+
def __init__(self, settings=None):
140+
self._djdt_wrap = True
141+
super().__init__(settings=settings)
145142

146-
class CacheHandlerPatch(CacheHandler):
147-
def __getitem__(self, alias):
148-
actual_cache = super().__getitem__(alias)
143+
def create_connection(self, alias):
144+
actual_cache = super().create_connection(alias)
145+
if self._djdt_wrap:
149146
return CacheStatTracker(actual_cache)
150-
151-
else:
152-
153-
class CacheHandlerPatch(CacheHandler):
154-
def __init__(self, settings=None):
155-
self._djdt_wrap = True
156-
super().__init__(settings=settings)
157-
158-
def create_connection(self, alias):
159-
actual_cache = super().create_connection(alias)
160-
if self._djdt_wrap:
161-
return CacheStatTracker(actual_cache)
162-
else:
163-
return actual_cache
147+
else:
148+
return actual_cache
164149

165150

166151
middleware_cache.caches = CacheHandlerPatch()
@@ -268,40 +253,26 @@ def title(self):
268253
)
269254

270255
def enable_instrumentation(self):
271-
if django.VERSION < (3, 2):
272-
if isinstance(middleware_cache.caches, CacheHandlerPatch):
273-
cache.caches = middleware_cache.caches
274-
else:
275-
cache.caches = CacheHandlerPatch()
276-
else:
277-
for alias in cache.caches:
278-
if not isinstance(cache.caches[alias], CacheStatTracker):
279-
cache.caches[alias] = CacheStatTracker(cache.caches[alias])
256+
for alias in cache.caches:
257+
if not isinstance(cache.caches[alias], CacheStatTracker):
258+
cache.caches[alias] = CacheStatTracker(cache.caches[alias])
280259

281-
if not isinstance(middleware_cache.caches, CacheHandlerPatch):
282-
middleware_cache.caches = cache.caches
260+
if not isinstance(middleware_cache.caches, CacheHandlerPatch):
261+
middleware_cache.caches = cache.caches
283262

284263
# Wrap the patched cache inside Django's ConnectionProxy
285264
if ConnectionProxy:
286265
cache.cache = ConnectionProxy(cache.caches, DEFAULT_CACHE_ALIAS)
287266

288267
def disable_instrumentation(self):
289-
if django.VERSION < (3, 2):
290-
cache.caches = original_caches
291-
cache.cache = original_cache
292-
# While it can be restored to the original, any views that were
293-
# wrapped with the cache_page decorator will continue to use a
294-
# monkey patched cache.
295-
middleware_cache.caches = original_caches
296-
else:
297-
for alias in cache.caches:
298-
if isinstance(cache.caches[alias], CacheStatTracker):
299-
cache.caches[alias] = cache.caches[alias].cache
300-
if ConnectionProxy:
301-
cache.cache = ConnectionProxy(cache.caches, DEFAULT_CACHE_ALIAS)
302-
# While it can be restored to the original, any views that were
303-
# wrapped with the cache_page decorator will continue to use a
304-
# monkey patched cache.
268+
for alias in cache.caches:
269+
if isinstance(cache.caches[alias], CacheStatTracker):
270+
cache.caches[alias] = cache.caches[alias].cache
271+
if ConnectionProxy:
272+
cache.cache = ConnectionProxy(cache.caches, DEFAULT_CACHE_ALIAS)
273+
# While it can be restored to the original, any views that were
274+
# wrapped with the cache_page decorator will continue to use a
275+
# monkey patched cache.
305276

306277
def generate_stats(self, request, response):
307278
self.record_stats(

debug_toolbar/panels/settings.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,12 @@
11
from collections import OrderedDict
22

3-
import django
43
from django.conf import settings
54
from django.utils.translation import gettext_lazy as _
5+
from django.views.debug import get_default_exception_reporter_filter
66

77
from debug_toolbar.panels import Panel
88

9-
if django.VERSION >= (3, 1):
10-
from django.views.debug import get_default_exception_reporter_filter
11-
12-
get_safe_settings = get_default_exception_reporter_filter().get_safe_settings
13-
else:
14-
from django.views.debug import get_safe_settings
9+
get_safe_settings = get_default_exception_reporter_filter().get_safe_settings
1510

1611

1712
class SettingsPanel(Panel):

docs/changes.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Change log
44
Next version
55
------------
66

7-
* Removed support for Django 3.1.
7+
* Removed support for Django < 3.2.
88

99
3.2.4 (2021-12-15)
1010
------------------

setup.cfg

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ classifiers =
1414
Development Status :: 5 - Production/Stable
1515
Environment :: Web Environment
1616
Framework :: Django
17-
Framework :: Django :: 2.2
1817
Framework :: Django :: 3.2
1918
Framework :: Django :: 4.0
2019
Intended Audience :: Developers
@@ -33,7 +32,7 @@ classifiers =
3332
[options]
3433
python_requires = >=3.6
3534
install_requires =
36-
Django >= 2.2
35+
Django >= 3.2
3736
sqlparse >= 0.2.0
3837
packages = find:
3938
include_package_data = true

tests/commands/test_debugsqlshell.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
import io
22
import sys
33

4-
import django
54
from django.contrib.auth.models import User
65
from django.core import management
76
from django.db import connection
87
from django.test import TestCase
98
from django.test.utils import override_settings
109

11-
if connection.vendor == "postgresql" and django.VERSION >= (3, 0, 0):
10+
if connection.vendor == "postgresql":
1211
from django.db.backends.postgresql import base as base_module
1312
else:
1413
from django.db.backends import utils as base_module

tests/models.py

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from django.conf import settings
22
from django.db import models
3+
from django.db.models import JSONField
34

45

56
class NonAsciiRepr:
@@ -11,19 +12,8 @@ class Binary(models.Model):
1112
field = models.BinaryField()
1213

1314

14-
try:
15-
from django.db.models import JSONField
16-
except ImportError: # Django<3.1
17-
try:
18-
from django.contrib.postgres.fields import JSONField
19-
except ImportError: # psycopg2 not installed
20-
JSONField = None
21-
22-
23-
if JSONField:
24-
25-
class PostgresJSON(models.Model):
26-
field = JSONField()
15+
class PostgresJSON(models.Model):
16+
field = JSONField()
2717

2818

2919
if settings.USE_GIS:

tests/panels/test_sql.py

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,7 @@
1515
from debug_toolbar import settings as dt_settings
1616

1717
from ..base import BaseTestCase
18-
19-
try:
20-
from psycopg2._json import Json as PostgresJson
21-
except ImportError:
22-
PostgresJson = None
23-
24-
if connection.vendor == "postgresql":
25-
from ..models import PostgresJSON as PostgresJSONModel
26-
else:
27-
PostgresJSONModel = None
18+
from ..models import PostgresJSON
2819

2920

3021
class SQLPanelTestCase(BaseTestCase):
@@ -138,12 +129,9 @@ def test_param_conversion(self):
138129
# ensure query was logged
139130
self.assertEqual(len(self.panel._queries), 3)
140131

141-
if (
142-
django.VERSION >= (3, 1)
143-
# Django 4.1 started passing true/false back for boolean
144-
# comparisons in MySQL.
145-
and not (django.VERSION >= (4, 1) and connection.vendor == "mysql")
146-
):
132+
# Django 4.1 started passing true/false back for boolean
133+
# comparisons in MySQL.
134+
if not (django.VERSION >= (4, 1) and connection.vendor == "mysql"):
147135
self.assertEqual(
148136
tuple([q[1]["params"] for q in self.panel._queries]),
149137
('["Foo"]', "[10, 1]", '["2017-12-22 16:07:01"]'),
@@ -160,7 +148,7 @@ def test_param_conversion(self):
160148
def test_json_param_conversion(self):
161149
self.assertEqual(len(self.panel._queries), 0)
162150

163-
list(PostgresJSONModel.objects.filter(field__contains={"foo": "bar"}))
151+
list(PostgresJSON.objects.filter(field__contains={"foo": "bar"}))
164152

165153
response = self.panel.process_request(self.request)
166154
self.panel.generate_stats(self.request, response)
@@ -171,11 +159,6 @@ def test_json_param_conversion(self):
171159
self.panel._queries[0][1]["params"],
172160
'["{\\"foo\\": \\"bar\\"}"]',
173161
)
174-
if django.VERSION < (3, 1):
175-
self.assertIsInstance(
176-
self.panel._queries[0][1]["raw_params"][0],
177-
PostgresJson,
178-
)
179162

180163
def test_binary_param_force_text(self):
181164
self.assertEqual(len(self.panel._queries), 0)

0 commit comments

Comments
 (0)