Skip to content

Fix Django 1.0 middleware function compatibility #879

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 17, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion debug_toolbar/apps.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from __future__ import absolute_import, unicode_literals

import inspect

from django.apps import AppConfig
from django.conf import settings
from django.core.checks import Error, register
Expand Down Expand Up @@ -63,4 +65,7 @@ def is_middleware_class(middleware_class, middleware_path):
middleware_cls = import_string(middleware_path)
except ImportError:
return
return issubclass(middleware_cls, middleware_class)
return (
inspect.isclass(middleware_cls) and
issubclass(middleware_cls, middleware_class)
)
7 changes: 7 additions & 0 deletions tests/middleware.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
def simple_middleware(get_response):
"""
Used to test Django 1.10 compatibility.
"""
def middleware(request):
return get_response(request)
return middleware
16 changes: 16 additions & 0 deletions tests/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import unittest
from xml.etree import ElementTree as ET

import django
from django.contrib.staticfiles.testing import StaticLiveServerTestCase
from django.core.checks import Error, run_checks
from django.test import RequestFactory, TestCase
Expand Down Expand Up @@ -243,3 +244,18 @@ def test_check_gzip_middleware_error(self):
),
]
)

@override_settings(
MIDDLEWARE=[
'debug_toolbar.middleware.DebugToolbarMiddleware',
'tests.middleware.simple_middleware',
],
MIDDLEWARE_CLASSES=None
)
def test_middleware_factory_functions_supported(self):
messages = run_checks()

if django.VERSION[:2] < (1, 10):
self.assertEqual(messages, [])
else:
self.assertEqual(messages[0].id, '1_10.W001')