Skip to content

Commit 1abb4f8

Browse files
committed
Update models.py
When using the request middleware, if the user is anonymous an error is raised stating that the 'history_user' attribute must be an instance of User. As this field can be null, get_history_user has been updated to return None if the user is not authenticated. Also made the returning of None explicit.
1 parent 6c5bc94 commit 1abb4f8

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

simple_history/models.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,9 +233,11 @@ def get_history_user(self, instance):
233233
return instance._history_user
234234
except AttributeError:
235235
try:
236-
return self.thread.request.user
236+
if self.thread.request.user.is_authenticated():
237+
return self.thread.request.user
238+
return None
237239
except AttributeError:
238-
return
240+
return None
239241

240242

241243
class ForeignKeyMixin(object):

0 commit comments

Comments
 (0)