django / channels

Developer-friendly asynchrony for Django

Home Page:https://channels.readthedocs.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

AttributeError: 'RedisChannelLayer' object has no attribute 'group_disgard'

messizqin opened this issue · comments

refers to this SO post: https://stackoverflow.com/questions/72885703/attributeerror-redischannellayer-object-has-no-attribute-group-disgard

traceback

  File "/Applications/MAMP/htdocs/canvas/src/zzd/env/lib/python3.7/site-packages/channels/generic/websocket.py", line 238, in websocket_disconnect
    await self.disconnect(message["code"])
  File "/Applications/MAMP/htdocs/canvas/src/zzd/zzd/notes/consumers.py", line 20, in disconnect
    await self.channel_layer.group_disgard(
AttributeError: 'RedisChannelLayer' object has no attribute 'group_disgard'

consumer

class NoteConsumer(AsyncJsonWebsocketConsumer):
    async def connect(self):
        self.room_name = self.scope['url_route']['kwargs']['pk']
        self.room_group_name = 'note_%s' % self.room_name

        await self.channel_layer.group_add(
            self.room_group_name, 
            self.channel_name, 
        ) 

        await self.accept()
    
    async def disconnect(self, close_code):
        await self.channel_layer.group_disgard(
            self.room_group_name, 
            self.channel_name, 
        )

    async def receive(self, text_data=None, bytes_data=None):
        text_data_json = json.loads(text_data)
        message = text_data_json['message']

        await self.channel_layer.group_send(
            self.room_group_name, 
            {
                'type': 'system_message', 
                'message': message, 
            }
        )

    async def system_message(self, event):
        # print(event)
        message = event['message']

        await self.send(text_data=json.dumps({
            'message': message, 
        }))

versions

(env) 🌹 python
Python 3.7.11 (default, Jul 27 2021, 07:03:16) 
[Clang 10.0.0 ] :: Anaconda, Inc. on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import django
>>> import channels
>>> import asgiref
>>> django.__version__
'3.2.8'
>>> channels.__version__
'3.0.5'
>>> asgiref.__version__
'3.3.4'

config

CHANNEL_LAYERS = {
    'default': {
        'BACKEND': 'channels_redis.core.RedisChannelLayer',
        'CONFIG': {
            "hosts": [('127.0.0.1', 6379)],
        },
    },
}

Why the method is undefined, how can I dismiss the bug?

group_disgard is not part part of the Channel Layer API. Nor has it ever been.

thank you for your reply, I used code from that site exactly ,in the documentation site you referenced, please press ctrl+f search for group_disgard, you will find it is included:

class ChatConsumer(WebsocketConsumer):

    def connect(self):
        async_to_sync(self.channel_layer.group_add)("chat", self.channel_name)

    def disconnect(self, close_code):
        async_to_sync(self.channel_layer.group_discard)("chat", self.channel_name)

I wonder who to discard the group in channel layer if there is 'no such a method'.

discard VS disgard by the looks of it.