inherit rather than monkey patch

* Enable migration in progress page in ALL environments
This commit is contained in:
chris meyers
2018-03-02 12:37:48 -05:00
parent 746a2c1eea
commit 36d59651af
3 changed files with 19 additions and 17 deletions

View File

@@ -239,6 +239,7 @@ TEMPLATES = [
] ]
MIDDLEWARE_CLASSES = ( # NOQA MIDDLEWARE_CLASSES = ( # NOQA
'awx.main.middleware.MigrationRanCheckMiddleware',
'awx.main.middleware.TimingMiddleware', 'awx.main.middleware.TimingMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.locale.LocaleMiddleware', 'django.middleware.locale.LocaleMiddleware',

View File

@@ -89,8 +89,6 @@ settings_files = os.path.join(settings_dir, '*.py')
settings_file = os.environ.get('AWX_SETTINGS_FILE', settings_file = os.environ.get('AWX_SETTINGS_FILE',
'/etc/tower/settings.py') '/etc/tower/settings.py')
MIDDLEWARE_CLASSES = ('awx.main.middleware.MigrationRanCheckMiddleware',) + MIDDLEWARE_CLASSES
# Attempt to load settings from /etc/tower/settings.py first, followed by # Attempt to load settings from /etc/tower/settings.py first, followed by
# /etc/tower/conf.d/*.py. # /etc/tower/conf.d/*.py.
try: try:

View File

@@ -9,8 +9,7 @@ from awx import prepare_env, MODE
prepare_env() prepare_env()
from django.core.handlers.base import BaseHandler # NOQA from django.core.wsgi import WSGIHandler # NOQA
from django.core.wsgi import get_wsgi_application # NOQA
import django # NOQA import django # NOQA
from django.conf import settings # NOQA from django.conf import settings # NOQA
from django.urls import resolve # NOQA from django.urls import resolve # NOQA
@@ -38,8 +37,8 @@ if MODE == 'production':
if django.__version__ != '1.11.7': if django.__version__ != '1.11.7':
raise RuntimeError("Django version other than 1.11.7 detected {}. \ raise RuntimeError("Django version other than 1.11.7 detected {}. \
Monkey Patch to support short-circuit Django Middelware \ Inherit from WSGIHandler to support short-circuit Django Middelware. \
is known to work for Django 1.11.7 and may not work with other, \ This is known to work for Django 1.11.7 and may not work with other, \
even minor, versions.".format(django.__version__)) even minor, versions.".format(django.__version__))
@@ -48,20 +47,24 @@ if settings.MIDDLEWARE:
The 'migration in progress' view feature short-circuits OLD Django \ The 'migration in progress' view feature short-circuits OLD Django \
MIDDLEWARE_CLASSES behavior. With the new Django MIDDLEWARE beahvior \ MIDDLEWARE_CLASSES behavior. With the new Django MIDDLEWARE beahvior \
it's possible to short-ciruit the middleware onion through supported \ it's possible to short-ciruit the middleware onion through supported \
middleware mechanisms. The monkey patch wrapper below should be removed.") middleware mechanisms. Further, from django.core.wsgi.get_wsgi_application() \
should be called to get an instance of WSGIHandler().")
def _wrapper_legacy_get_response(self, request): class AWXWSGIHandler(WSGIHandler):
# short-circuit middleware def _legacy_get_response(self, request):
if getattr(resolve(request.path), 'url_name', '') == 'migrations_notran': # short-circuit middleware
return self._get_response(request) if getattr(resolve(request.path), 'url_name', '') == 'migrations_notran':
# fall through to middle-ware return self._get_response(request)
else: # fall through to middle-ware
return self._real_legacy_get_response(request) else:
return super(AWXWSGIHandler, self)._legacy_get_response(request)
BaseHandler._real_legacy_get_response = BaseHandler._legacy_get_response
BaseHandler._legacy_get_response = _wrapper_legacy_get_response
# Return the default Django WSGI application. # Return the default Django WSGI application.
def get_wsgi_application():
django.setup(set_prefix=False)
return AWXWSGIHandler()
application = get_wsgi_application() application = get_wsgi_application()