Commit 38a9c459 authored by Daniel Klaffenbach's avatar Daniel Klaffenbach 🐍

development.middleware: Issue warning instead of raising exception

Raising an exception depending on `settings.DEBUG` turned out to be a bad
idea, as it breaks tests. We could try to detect Django's test mode and
surpress the exception, but that might not be reliable either.

So the best thing to do in that case is to issue a warning through Python's
logging system.
parent 2b4e828c
Pipeline #3837 passed with stage
in 33 seconds
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
import logging
from django.conf import settings
from django.contrib.auth.middleware import RemoteUserMiddleware
from django.core.exceptions import ImproperlyConfigured
class LocalUserMiddleware(RemoteUserMiddleware):
"""
......@@ -19,4 +19,5 @@ class LocalUserMiddleware(RemoteUserMiddleware):
super(LocalUserMiddleware, self).__init__(*args, **kwargs)
# Prevent accidental usage in production environments
if settings.DEBUG == False:
raise ImproperlyConfigured('The LocalUserMiddleware cannot be used in production environments!')
logger = logging.getLogger(__name__)
logger.warning('The LocalUserMiddleware should never be used in production environments!')
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment