Skip to content

Commit a6b64ca

Browse files
Mohammad Rabetianmatthiask
Mohammad Rabetian
authored andcommitted
added warning for incompatibility with middleware_classes setting. (#1217)
* added warning for incompatibility with middleware_classes setting. * added test for middleware_classes error check
1 parent d098d5a commit a6b64ca

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

debug_toolbar/apps.py

+11
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,17 @@ def check_middleware(app_configs, **kwargs):
2121
gzip_index = None
2222
debug_toolbar_indexes = []
2323

24+
# If old style MIDDLEWARE_CLASSES is being used, report an error.
25+
if settings.is_overridden("MIDDLEWARE_CLASSES"):
26+
errors.append(
27+
Warning(
28+
"debug_toolbar is incompatible with MIDDLEWARE_CLASSES setting.",
29+
hint="Use MIDDLEWARE instead of MIDDLEWARE_CLASSES",
30+
id="debug_toolbar.W004",
31+
)
32+
)
33+
return errors
34+
2435
# Determine the indexes which gzip and/or the toolbar are installed at
2536
for i, middleware in enumerate(settings.MIDDLEWARE):
2637
if is_middleware_class(GZipMiddleware, middleware):

tests/test_integration.py

+20
Original file line numberDiff line numberDiff line change
@@ -411,3 +411,23 @@ def test_check_gzip_middleware_error(self):
411411
)
412412
],
413413
)
414+
415+
@override_settings(
416+
MIDDLEWARE_CLASSES=[
417+
"django.contrib.messages.middleware.MessageMiddleware",
418+
"django.contrib.sessions.middleware.SessionMiddleware",
419+
"django.contrib.auth.middleware.AuthenticationMiddleware",
420+
"django.middleware.gzip.GZipMiddleware",
421+
"debug_toolbar.middleware.DebugToolbarMiddleware",
422+
]
423+
)
424+
def test_check_middleware_classes_error(self):
425+
messages = run_checks()
426+
self.assertIn(
427+
Warning(
428+
"debug_toolbar is incompatible with MIDDLEWARE_CLASSES setting.",
429+
hint="Use MIDDLEWARE instead of MIDDLEWARE_CLASSES",
430+
id="debug_toolbar.W004",
431+
),
432+
messages,
433+
)

0 commit comments

Comments
 (0)