Skip to content

Commit

Permalink
Raise MiddlewareNotUsed in deprecated FlagConditionsMiddleware
Browse files Browse the repository at this point in the history
Per the [Django documentation](https://docs.djangoproject.com/en/2.2/topics/http/middleware/#marking-middleware-as-unused) on marking middle as unused, this change raises `MiddlewareNotUsed` when initializing the deprecated `FlagConditionsMiddleware`. This way, Django takes the middleware out of the middleware process and the fact that this middleware no longer calls `get_response` and returns it for a request will not interrupt the flow of the request through other middleware.
  • Loading branch information
willbarton committed Jun 2, 2020
1 parent a275cf1 commit 2c48f44
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
5 changes: 4 additions & 1 deletion flags/middleware.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import warnings

from django.core.exceptions import MiddlewareNotUsed


class FlagConditionsMiddleware:
def __init__(self, get_response):
Expand All @@ -8,6 +10,7 @@ def __init__(self, get_response):
"effect. It will be removed in a future version of Django-Flags. ",
FutureWarning,
)
raise MiddlewareNotUsed

def __call__(self, request):
pass
pass # pragma: no cover
4 changes: 3 additions & 1 deletion flags/tests/test_middleware.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import warnings

from django.core.exceptions import MiddlewareNotUsed
from django.test import SimpleTestCase

from flags.middleware import FlagConditionsMiddleware
Expand All @@ -8,7 +9,8 @@
class FlagConditionsMiddlewareTests(SimpleTestCase):
def test_middleware_raises_warning(self):
with warnings.catch_warnings(record=True) as warning_list:
FlagConditionsMiddleware(None)
with self.assertRaises(MiddlewareNotUsed):
FlagConditionsMiddleware(None)

self.assertEqual(len(warning_list), 1)
self.assertEqual(warning_list[0].category, FutureWarning)

0 comments on commit 2c48f44

Please sign in to comment.