fix(backend):AttributeError: 'AnonymousUser' object has no attribute 'get_channels_groups'

This commit is contained in:
Petitminion 2025-06-04 02:36:11 +02:00 committed by petitminion
parent 724d85a2d9
commit 34203afe44
1 changed files with 5 additions and 1 deletions

View File

@ -19,6 +19,10 @@ class JsonAuthConsumer(JsonWebsocketConsumer):
channels.group_add(group, self.channel_name)
def disconnect(self, close_code):
groups = self.scope["user"].get_channels_groups() + self.groups
if self.scope.get("user", False) and self.scope.get("user").pk is not None:
groups = self.scope["user"].get_channels_groups() + self.groups
else:
groups = self.groups
for group in groups:
channels.group_discard(group, self.channel_name)