emmett-framework / granian

A Rust HTTP server for Python applications
BSD 3-Clause "New" or "Revised" License
2.67k stars 79 forks source link

Error Django Channels #213

Closed ancs21 closed 6 months ago

ancs21 commented 7 months ago

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'
gi0baro commented 7 months ago

@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.

gi0baro commented 6 months ago

@ancs21 I saw the reply in https://github.com/strawberry-graphql/strawberry/issues/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.