File tree 2 files changed +31
-0
lines changed
2 files changed +31
-0
lines changed Original file line number Diff line number Diff line change @@ -21,6 +21,17 @@ def check_middleware(app_configs, **kwargs):
21
21
gzip_index = None
22
22
debug_toolbar_indexes = []
23
23
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
+
24
35
# Determine the indexes which gzip and/or the toolbar are installed at
25
36
for i , middleware in enumerate (settings .MIDDLEWARE ):
26
37
if is_middleware_class (GZipMiddleware , middleware ):
Original file line number Diff line number Diff line change @@ -411,3 +411,23 @@ def test_check_gzip_middleware_error(self):
411
411
)
412
412
],
413
413
)
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
+ )
You can’t perform that action at this time.
0 commit comments