Closed
Bug 1412797
Opened 7 years ago
Closed 7 years ago
Switch to the Django 1.10+ new style middleware API
Categories
(Tree Management :: Treeherder, enhancement, P3)
Tree Management
Treeherder
Tracking
(Not tracked)
RESOLVED
FIXED
People
(Reporter: emorley, Assigned: emorley)
References
Details
(Keywords: perf)
Attachments
(1 file)
Django 1.10 changed the way middleware works, fixing a number of issues and improving performance (eg due to short-circuiting changes, which help with WhiteNoise).
However these changes are backwards incompatible, so only take effect when using a new `MIDDLEWARE` option in settings.py. Anything using the old `MIDDLEWARE_CLASSES` setting is run in the old, less performant manner.
Before we can just s/MIDDLEWARE_CLASSES/MIDDLEWARE/ in our settings.py, we need to ensure all the middleware we use is actually compatible with the new API. See:
https://docs.djangoproject.com/en/1.11/topics/http/middleware/#upgrading-middleware
We use the following non-native-Django middleware:
* treeherder.middleware.NewRelicMiddleware:
-> Will need adjusting: https://github.com/mozilla/treeherder/blob/f7380546f8cf54f3830718575f6bae6b903f4257/treeherder/middleware.py#L54-L61
* treeherder.middleware.CustomWhiteNoise (subclass of WhiteNoise):
-> Already compatible (https://github.com/evansd/whitenoise/blob/v3.3.1/whitenoise/middleware.py#L8-L26)
* debug_toolbar.middleware.DebugToolbarMiddleware:
-> Already compatible (https://github.com/jazzband/django-debug-toolbar/blob/1.8/debug_toolbar/middleware.py#L19-L23)
* corsheaders.middleware.CorsMiddleware:
-> Already compatible (https://github.com/ottoyiu/django-cors-headers/blob/2.1.0/corsheaders/compat.py#L1-L6)
* hawkrest.middleware.HawkResponseMiddleware:
-> Will need fixing: https://github.com/kumar303/hawkrest/issues/38#issuecomment-340293738
Assignee | ||
Updated•7 years ago
|
Comment 1•7 years ago
|
||
Assignee | ||
Updated•7 years ago
|
Attachment #8949730 -
Flags: review?(cdawson)
Updated•7 years ago
|
Attachment #8949730 -
Flags: review?(cdawson) → review+
Comment 2•7 years ago
|
||
Commits pushed to master at https://github.com/mozilla/treeherder
https://github.com/mozilla/treeherder/commit/d256834a2a1909d77a95164480c88dc4230414af
Bug 1412797 - Adapt NewRelicMiddleware for the new middleware API
Makes the middleware compatible with the new-style Django middleware
API, ready for switching to it in a later commit. See:
https://docs.djangoproject.com/en/1.11/topics/http/middleware/#upgrading-middleware
https://github.com/mozilla/treeherder/commit/292a2777b80397cecefcd500db6f8dc7123bc878
Bug 1412797 - Adapt HawkResponseMiddleware for the new middleware API
Makes the middleware compatible with the new-style Django middleware
API, which hasn't yet happened upstream:
https://github.com/kumar303/hawkrest/issues/38
https://github.com/mozilla/treeherder/commit/58e6690e645de083f0aa0430b31f02510b57cec2
Bug 1412797 - Switch to Django's new middleware API
The old API (`MIDDLEWARE_CLASSES`) has been deprecated in favour of
the `MIDDLEWARE` pref. The new API is faster (since it short-circuits)
and has more sensible error handling characteristics.
See:
https://github.com/django/deps/blob/master/final/0005-improved-middleware.rst
https://docs.djangoproject.com/en/1.11/topics/http/middleware/#upgrading-middleware
Since the new API short-circuits (that is, doesn't run later middleware
if an earlier one returns a response), `XFrameOptionsMiddleware` and
`CorsMiddleware` must be moved to before the WhiteNoise middleware,
to ensure the headers are still set like before - even when WhiteNoise
returns early for static content. (Whilst most static content doesn't
need CORS headers, `revision.txt` and `contribute.json` do.)
Assignee | ||
Updated•7 years ago
|
Status: ASSIGNED → RESOLVED
Closed: 7 years ago
Resolution: --- → FIXED
You need to log in
before you can comment on or make changes to this bug.
Description
•