Browse Source

handle edgecase crashing our tests with search middleware

Rafał Pitoń 7 years ago
parent
commit
2ced576c70
1 changed files with 10 additions and 2 deletions
  1. 10 2
      misago/search/context_processors.py

+ 10 - 2
misago/search/context_processors.py

@@ -7,8 +7,16 @@ from .searchproviders import searchproviders
 
 
 def search_providers(request):
 def search_providers(request):
     allowed_providers = []
     allowed_providers = []
-    if request.user.acl_cache['can_search']:
-        allowed_providers = searchproviders.get_allowed_providers(request)
+
+    try:
+        if request.user.acl_cache['can_search']:
+            allowed_providers = searchproviders.get_allowed_providers(request)
+    except AttributeError:
+        # is user has no acl_cache, cease entire middleware
+        # this is edge case that occurs when debug toolbar intercepts
+        # the redirect response from logout page and runs context providers
+        # with non-misago's anonymous user model that hos acl support
+        return {}
 
 
     request.frontend_context['SEARCH_API'] = reverse('misago:api:search')
     request.frontend_context['SEARCH_API'] = reverse('misago:api:search')
     request.frontend_context['SEARCH_PROVIDERS'] = []
     request.frontend_context['SEARCH_PROVIDERS'] = []