Problem with sending django channels event from models

60 views
Skip to first unread message

luan fonceca

unread,
Jul 26, 2018, 4:11:00 PM7/26/18
to Django users
Hello, i'm trying to implement a "post_save" signal wherever some user are update. I setup everything by following the documentation and some tutorials for Channels 2. I wrote a test using "py.test" to assert that everything is working as expected but i'm getting a exception.


Thanks in advance.

Andrew Godwin

unread,
Jul 27, 2018, 6:30:31 PM7/27/18
to django...@googlegroups.com
You need to post the full traceback, not just the last section. I suspect what you are doing is calling model methods directly in an async function, but I can't confirm that without a full traceback.

Andrew

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/3f42ad5c-c737-4a5e-baad-54023261d7f5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

luan fonceca

unread,
Jul 31, 2018, 9:14:23 AM7/31/18
to django...@googlegroups.com
Hello Andrew, sorry for the lack of traceback on the gist. I have changed my code a bit, i was using the `async_to_sync` but now i'm using this way inside my User save method:

channel_layer = get_channel_layer()
channel_layer.group_send(
    'users_{}'.format(self.pk), {
        'type': 'users.post_save',
        'user_pk': self.pk
    }
)

And everything works fine, but my tests are raising warnings on each test, like this, if you want to see the full traceback of my test, click here:

users/tests/test_consumers.py::test_user_consumer
  /Users/luan/Sources/channels-test/users/models.py:56: RuntimeWarning: coroutine 'RedisChannelLayer.group_send' was never awaited
    'user_pk': self.pk

I have update my gist, if you want to see something else, but in general i'm using py.test, as you can see in here.



Thanks for everything, Andrew.

You received this message because you are subscribed to a topic in the Google Groups "Django users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/django-users/3hZUiOvhSfE/unsubscribe.
To unsubscribe from this group and all its topics, send an email to django-users...@googlegroups.com.

To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.

Andrew Godwin

unread,
Jul 31, 2018, 4:54:42 PM7/31/18
to django...@googlegroups.com
Yes, you can't just call "group_send" without awaiting it, or you'll get those warnings. You need async_to_sync, I'm afraid. Otherwise, you're not actually waiting for the group_send function to finish and you'll start getting some unreliable test results.

Andrew

Reply all
Reply to author
Forward
0 new messages