Repository: django/channels

Issue:
asgiref dependency should be updated; channels 3.0.3 requires min. 3.2.10, which doesn't work for background workers
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()`.


Discussion:
Hi, could you provide minimal reproducible example please? 
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'
```
Yes, it needs this fix:

https://github.com/django/asgiref/commit/ee967d2e3be77bb4c5082542a538e1c77a37a031

Updating asgiref should solve your issue. 

Want to make a PR raising the minimum? 

Thanks. 
Happy to, will create a PR to raise the minimum to 3.3.1.

Resolving patch:
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -14,7 +14,7 @@
     python_requires='>=3.6',
     install_requires=[
         'Django>=2.2',
-        'asgiref>=3.2.10,<4',
+        'asgiref>=3.3.1,<4',
         'daphne>=3.0,<4',
     ],
     extras_require={


Test patch: