asgiref: [possible bug] 'code' is not labeled as optional

In https://asgi.readthedocs.io/en/latest/specs/www.html#disconnect-receive-event-ws it does not say code is optional, yet it says “as per websocket spec”, where code is optional (“may contain”). Later on in Close - send event it explicitly mentions that the code there is optional. In the first link should code be optional or required?

If code is optional I would be happy to submit a PR to this repo to update the docs.

This is not just a theoretical question, as we are facing a bug that may be related to this. In https://github.com/django/channels/blob/38324816c115567e198a573bc294d8345df5e8a9/channels/generic/websocket.py#L105 channels assumes that the code key exists, but in our case it doesn’t exist and a KeyError is raised.

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 16 (13 by maintainers)

Commits related to this issue

Most upvoted comments

@carltongibson, sure. I figure I might as well make the proposal a PR because the change is so easy to make: https://github.com/django/channels/pull/1905

Yeah, both of those should be, since they are disconnect. disconnect = 1005, close = 1000 as defaults.

So should channels default the value to 1005, then? Or maybe Uvicorn should specify code (link)? Or both?

Uvicorn team is already aware of this. 👀 There’s a PR in WIP adding the code on those. 🙏