From 20c2bd71f8638b7f6523baf25b89d730a8c204f2 Mon Sep 17 00:00:00 2001 From: cuom1999 Date: Mon, 20 Dec 2021 18:55:26 -0600 Subject: [PATCH] Fix out of range bug --- chat_box/views.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/chat_box/views.py b/chat_box/views.py index 5709dfe..2ed2bb7 100644 --- a/chat_box/views.py +++ b/chat_box/views.py @@ -408,11 +408,13 @@ def get_unread_count(rooms, user): .order_by().values('room')\ .annotate(unread_count=Count('pk')).values('unread_count') - return UserRoom.objects\ + res = UserRoom.objects\ .filter(user=user, room__isnull=True)\ .annotate( unread_count=Coalesce(Subquery(mess, output_field=IntegerField()), 0), - ).values_list('unread_count', flat=True)[0] + ).values_list('unread_count', flat=True) + + return res[0] if len(res) else 0 @login_required