(bugfix) Adds hasattr check before threadlocal.auditlog access in set_actor

middleware.set_actor was inconsistent with other methods in checking for
hasattr(threadlocal, 'auditlog')
This commit is contained in:
Stephen Mc Guinness 2018-01-04 19:07:13 +00:00 committed by Ryan Castner
parent 31db99497a
commit 881b7326bd

View file

@ -70,14 +70,15 @@ class AuditlogMiddleware(MiddlewareMixin):
Signal receiver with an extra, required 'user' kwarg. This method becomes a real (valid) signal receiver when
it is curried with the actor.
"""
if signal_duid != threadlocal.auditlog['signal_duid']:
return
try:
app_label, model_name = settings.AUTH_USER_MODEL.split('.')
auth_user_model = apps.get_model(app_label, model_name)
except ValueError:
auth_user_model = apps.get_model('auth', 'user')
if sender == LogEntry and isinstance(user, auth_user_model) and instance.actor is None:
instance.actor = user
if hasattr(threadlocal, 'auditlog'):
if signal_duid != threadlocal.auditlog['signal_duid']:
return
try:
app_label, model_name = settings.AUTH_USER_MODEL.split('.')
auth_user_model = apps.get_model(app_label, model_name)
except ValueError:
auth_user_model = apps.get_model('auth', 'user')
if sender == LogEntry and isinstance(user, auth_user_model) and instance.actor is None:
instance.actor = user
instance.remote_addr = threadlocal.auditlog['remote_addr']