question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

asgiref dependency should be updated; channels 3.0.3 requires min. 3.2.10, which doesn't work for background workers

See original GitHub issue

Channels 3.0.3 depends on asgiref>=3.2.10, however with that version, background workers will fail with TypeError: __call__() missing 2 required positional arguments: 'receive' and 'send' when receiving a message, even if declared with .as_asgi().

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
mikarauniocommented, Jan 19, 2021

Channels 3.0.3 depends on asgiref>=3.2.10. However, when actually running with 3.2.10 (as can happen after an upgrade from Channels 2), background workers fail with TypeError: __call__() missing 2 required positional arguments: 'receive' and 'send' when receiving a message. This looks like the workers are not ASGI 3 compliant, even though they have been defined with .as_asgi() in routing.py. Manually upgrading asgiref to 3.3.1 resolves the issue. I have not tested interim versions to identify the actual minimum required vesion.

With 3.2.10, both SyncConsumer and AsyncConsumer workers fail. Groups however work fine.

This is with Debian 10.7, with stock Python 3.7.3. Packages:

aioredis==1.3.1
asgiref==3.2.10
channels==3.0.3
channels-redis==3.2.0
Django==3.1.5
hiredis==1.1.0

Minimal setup to reproduce:

settings.py:

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

routing.py:

from channels.routing import ProtocolTypeRouter, URLRouter, ChannelNameRouter
from channels.auth import AuthMiddlewareStack

application = ProtocolTypeRouter({
    'websocket': AuthMiddlewareStack(
        URLRouter([
            ...
        ]),
    ),
    'channel': ChannelNameRouter({
        'testworker': workers.TestWorker.as_asgi(),
    }),
})

workers.py:

from channels.consumer import SyncConsumer

class TestWorker(SyncConsumer):
    def test_action(self, message):
        print(message['data'])

Steps:

  • Run ./manage.py runworker testworker
  • From a Django shell, execute async_to_sync(channel_layer.send)('testworker', {'type': 'test.action', 'data': 'Test'})

Expected outcome:

  • runworker prints “Test” as with Channels 2.4.0

Actual outcome:

  • runworker crashes with the following traceback
Traceback (most recent call last):
  File "./manage.py", line 22, in <module>
    execute_from_command_line(sys.argv)
  File "/.../venv/lib/python3.7/site-packages/django/core/management/__init__.py", line 401, in execute_from_command_line
    utility.execute()
  File "/.../venv/lib/python3.7/site-packages/django/core/management/__init__.py", line 395, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/.../venv/lib/python3.7/site-packages/django/core/management/base.py", line 330, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/.../venv/lib/python3.7/site-packages/django/core/management/base.py", line 371, in execute
    output = self.handle(*args, **options)
  File "/.../venv/lib/python3.7/site-packages/channels/management/commands/runworker.py", line 46, in handle
    worker.run()
  File "/.../venv/lib/python3.7/site-packages/asgiref/server.py", line 60, in run
    event_loop.run_until_complete(self.handle())
  File "/usr/lib/python3.7/asyncio/base_events.py", line 584, in run_until_complete
    return future.result()
  File "/.../venv/lib/python3.7/site-packages/channels/worker.py", line 30, in handle
    [listener.result() for listener in listeners]
  File "/.../venv/lib/python3.7/site-packages/channels/worker.py", line 30, in <listcomp>
    [listener.result() for listener in listeners]
  File "/.../venv/lib/python3.7/site-packages/channels/worker.py", line 42, in listener
    instance_queue = self.get_or_create_application_instance(channel, scope)
  File "/.../venv/lib/python3.7/site-packages/asgiref/server.py", line 87, in get_or_create_application_instance
    application_instance = self.application(scope=scope)
TypeError: __call__() missing 2 required positional arguments: 'receive' and 'send'
0reactions
carltongibsoncommented, Jul 10, 2021

Closed in #1614

Read more comments on GitHub >

github_iconTop Results From Across the Web

asgiref dependency should be updated; channels 3.0.3 requires min ...
asgiref dependency should be updated; channels 3.0.3 requires min. 3.2.10, which doesn't work for background workers.
Read more >
32128 (Issue with asgiref dependency installing Django 3.1.x)
I installed asgiref first here just for demonstration. A straight pip install Django equally picks 3.2.10. I think this is a RB as...
Read more >
Issue with asgiref dependency installing Django 3.1.x
Successfully uninstalled asgiref-3.2.10. ERROR: After October 2020 you may experience errors when installing or updating packages. This is because pip will ...
Read more >
Recommended update for python-Sphinx, python-amqp ...
An update that has 5 recommended fixes can now be installed. Description: This update for python-Sphinx, python-amqp, python-asgiref, python-billiard, python- ...
Read more >
All NetBSD Packages
'GitHub' Username of the Current User; R-withr-2.5.0: Run code 'with' temporarily modified ... bsetroot-0.1nb7: Tools to set the root windows background ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found