From 941d3bec178b279a3f3eb93eb7005c1b96852354 Mon Sep 17 00:00:00 2001 From: Josh Schneier Date: Tue, 26 Jan 2016 01:37:05 -0500 Subject: [PATCH] Fixes #2120 - bail out of RedirectMiddleware if request.site is not set --- wagtail/wagtailredirects/middleware.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/wagtail/wagtailredirects/middleware.py b/wagtail/wagtailredirects/middleware.py index b88721b20b..fe2d3776bd 100644 --- a/wagtail/wagtailredirects/middleware.py +++ b/wagtail/wagtailredirects/middleware.py @@ -11,11 +11,16 @@ class RedirectMiddleware(object): if response.status_code != 404: return response + # If a middleware before `SiteMiddleware` returned a response the + # `site` attribute was never set, ref #2120 + if not hasattr(request, 'site'): + return response + # Get the path path = models.Redirect.normalise_path(request.get_full_path()) # Get the path without the query string or params - path_without_query = urlparse(path)[2] + path_without_query = urlparse(path).path # Find redirect try: