group_send does not work for a model instance
See original GitHub issueI am trying to use group_send using a model instance:
def group_send(moogt, notification):
    channel_layer = get_channel_layer()
    if moogt:
        async_to_sync(channel_layer.group_send)(f'{moogt.id}', notification)
Here notification, contains a model object like this:
notification = {
        'type': 'receive_group_message',
        'argument': argument,
        'event_type': message_type
    }
Of course, I do serialize the model object in the consumer, inside receive_group_message. But I am not getting anything in my websocket clients.
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (1 by maintainers)
 Top Results From Across the Web
Top Results From Across the Web
Cant send a message to a Django channel via group_send
Let me try to clear it up. When a client connects to the Channels server, a consumer instance or channel is created for...
Read more >Why doesn't my isinstance() work?
Hola, I'm having trouble getting a subclass to trigger an isinstance(). Code below: model.py excerpt: ------------ from django.db import models
Read more >Channel Layers — Channels 4.0.0 documentation
Channel layers allow you to talk between different instances of an application. They're a useful part of making a distributed realtime application if...
Read more >How Terrorist Groups End: Lessons for Countering al Qa'ida
2. Terrorism—Prevention—International cooperation. 3. Intelligence service. 4. Problem-oriented policing. 5. Qaida (Organization). I ...
Read more >Model instance reference - Django documentation
Issues an SQL DELETE for the object. This only deletes the object in the database; the Python instance will still exist and will...
Read more > Top Related Medium Post
Top Related Medium Post
No results found
 Top Related StackOverflow Question
Top Related StackOverflow Question
No results found
 Troubleshoot Live Code
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free Top Related Reddit Thread
Top Related Reddit Thread
No results found
 Top Related Hackernoon Post
Top Related Hackernoon Post
No results found
 Top Related Tweet
Top Related Tweet
No results found
 Top Related Dev.to Post
Top Related Dev.to Post
No results found
 Top Related Hashnode Post
Top Related Hashnode Post
No results found

group_sendbehaviour dependes on channel layer.If you use
InMemoryChannelLayerit is fine to leave model instances into messages. but if you useRedisChannelLayer(or any other channel layer which needs to interact with an external system) this is not possible anymore since message data needs to be serialized in the process. By default django model instances are not serializable by common used serializers (json/msgpack).You also need to serialize the model in your group_send before passing to channel layer.
However I would expect some errors to be thrown like “unable to serialize instance of <model>”, if you do not see any I suppose that the serializer you ara using is failing silently.
What @sevdog says is correct.
I don’t think there’s enough to really go on as a concrete issue.