operation_log: Fix logout generating AttributeError
When logging out request.user.is_authenticated() throws
AttributeError as request.user is NoneType and does not
contain required method.
This patch checks whether request.user is None and
takes a proper action.
Closes-Bug:
@@ -106,8 +106,10 @@ class OperationLogMiddleware(object):
def _get_log_format(self, request):
"""Return operation log format."""
- if not (hasattr(request, 'user') and
- request.user.is_authenticated()):
+ user = getattr(request, 'user', None)
+ if not user:
+ return
+ if not request.user.is_authenticated():
return
method = request.method.upper()
if not (method in self.target_methods):
