Skip to content

Commit

Permalink
(bugfix) Adds hasattr check before threadlocal.auditlog access in set…
Browse files Browse the repository at this point in the history
…_actor

middleware.set_actor was inconsistent with other methods in checking for
hasattr(threadlocal, 'auditlog')
  • Loading branch information
smokeyfish authored and audiolion committed Jan 4, 2018
1 parent 31db994 commit 881b732
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions src/auditlog/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,15 @@ def set_actor(user, sender, instance, signal_duid, **kwargs):
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']

0 comments on commit 881b732

Please sign in to comment.