Error Django Channels
ancs21 opened this issue · comments
I get error setup with Django Channels
File "/usr/local/lib/python3.11/site-packages/strawberry/channels/handlers/base.py", line 88, in dispatch
await super().dispatch(message)
File "/usr/local/lib/python3.11/site-packages/channels/consumer.py", line 73, in dispatch
await handler(message)
File "/usr/local/lib/python3.11/site-packages/channels/generic/websocket.py", line 173, in websocket_connect
await self.connect()
File "/usr/local/lib/python3.11/site-packages/strawberry/channels/handlers/ws_handler.py", line 77, in connect
preferred_protocol = self.pick_preferred_protocol(self.scope["subprotocols"])
~~~~~~~~~~^^^^^^^^^^^^^^^^
KeyError: 'subprotocols'
@ancs21 I actually think this is a strawberry issue.
It seems that their channels implementation expects the subprotocol
key to be in scope here https://github.com/strawberry-graphql/strawberry/blob/0.219.2/strawberry/channels/handlers/ws_handler.py#L77, but ASGI ref defines that key as optional, see https://asgi.readthedocs.io/en/latest/specs/www.html#websocket-connection-scope.
Maybe you can open an issue on strawberry repo and mention this one as the starting point.
@ancs21 I saw the reply in strawberry-graphql/strawberry#3386, I just opened #228, as even if strawberry solves the issue, their implementation won't probably work with Granian due to the lack of subprotocols support.
Closing this.