Avoid accessing an attribute of a NoneType object

remotes/origin/issue/4795/notification_even_they_are_disabled
luyikei 2016-02-21 16:45:53 +09:00 committed by Alejandro Alonso
parent 3c33c4e7cc
commit 8d4bd9d655
1 changed files with 7 additions and 6 deletions

View File

@ -239,13 +239,14 @@ class EditableWatchedResourceModelSerializer(WatchedResourceModelSerializer):
def to_native(self, obj):
#if watchers wasn't attached via the get_queryset of the viewset we need to manually add it
if obj is not None and not hasattr(obj, "watchers"):
obj.watchers = [user.id for user in obj.get_watchers()]
if obj is not None:
if not hasattr(obj, "watchers"):
obj.watchers = [user.id for user in obj.get_watchers()]
request = self.context.get("request", None)
user = request.user if request else None
if user and user.is_authenticated():
obj.is_watcher = user.id in obj.watchers
request = self.context.get("request", None)
user = request.user if request else None
if user and user.is_authenticated():
obj.is_watcher = user.id in obj.watchers
return super(WatchedResourceModelSerializer, self).to_native(obj)