{"action":"created","issue":{"url":"https://api.github.com/repos/django/channels/issues/1165","repository_url":"https://api.github.com/repos/django/channels","labels_url":"https://api.github.com/repos/django/channels/issues/1165/labels{/name}","comments_url":"https://api.github.com/repos/django/channels/issues/1165/comments","events_url":"https://api.github.com/repos/django/channels/issues/1165/events","html_url":"https://github.com/django/channels/issues/1165","id":366854510,"node_id":"MDU6SXNzdWUzNjY4NTQ1MTA=","number":1165,"title":"AsyncHttpConsumer doesn't have normal consumer attributes","user":{"login":"strexicious","id":13009365,"node_id":"MDQ6VXNlcjEzMDA5MzY1","avatar_url":"https://avatars1.githubusercontent.com/u/13009365?v=4","gravatar_id":"","url":"https://api.github.com/users/strexicious","html_url":"https://github.com/strexicious","followers_url":"https://api.github.com/users/strexicious/followers","following_url":"https://api.github.com/users/strexicious/following{/other_user}","gists_url":"https://api.github.com/users/strexicious/gists{/gist_id}","starred_url":"https://api.github.com/users/strexicious/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/strexicious/subscriptions","organizations_url":"https://api.github.com/users/strexicious/orgs","repos_url":"https://api.github.com/users/strexicious/repos","events_url":"https://api.github.com/users/strexicious/events{/privacy}","received_events_url":"https://api.github.com/users/strexicious/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-10-04T15:46:24Z","updated_at":"2018-10-04T20:31:09Z","closed_at":null,"author_association":"NONE","body":"I was trying to access `self.channel_name` and `self.channel_layer` within a consumer inherited from AsyncHttpConsumer and it raised exceptions saying that my consumer had no such attributes.\r\n\r\nHere is the toy code to reproduce this bug:\r\n\r\n**routing.py**\r\n```python\r\napplication = ProtocolTypeRouter({\r\n    \"http\": URLRouter([\r\n        url(r\"^test/me\", MeConsumer),\r\n        url(r\"\", AsgiHandler)\r\n    ])\r\n})\r\n```\r\n**consumers.py**\r\n```python\r\nclass MeConsumer(AsyncHttpConsumer):\r\n\r\n    async def handle(self, body):\r\n        my_channel_name = self.channel_name\r\n        self.channel_layer.group_add(\"my_group\", self.channel_name)\r\n        print(\"Here is the channel name:\", my_channel_name)\r\n        await asyncio.sleep(10)\r\n        await self.send_response(200, b\"Your response bytes\", headers=[\r\n            (\"Content-Type\", \"text/plain\"),\r\n        ])\r\n```\r\n\r\n*I couldn't help but peek into the source code, and I noticed that `AsyncHttpConsumer` overrides `__call__` of it's base class. I am not an expert but :eyes: it may be useful to know.*"},"comment":{"url":"https://api.github.com/repos/django/channels/issues/comments/427158864","html_url":"https://github.com/django/channels/issues/1165#issuecomment-427158864","issue_url":"https://api.github.com/repos/django/channels/issues/1165","id":427158864,"node_id":"MDEyOklzc3VlQ29tbWVudDQyNzE1ODg2NA==","user":{"login":"matthiask","id":2627,"node_id":"MDQ6VXNlcjI2Mjc=","avatar_url":"https://avatars1.githubusercontent.com/u/2627?v=4","gravatar_id":"","url":"https://api.github.com/users/matthiask","html_url":"https://github.com/matthiask","followers_url":"https://api.github.com/users/matthiask/followers","following_url":"https://api.github.com/users/matthiask/following{/other_user}","gists_url":"https://api.github.com/users/matthiask/gists{/gist_id}","starred_url":"https://api.github.com/users/matthiask/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/matthiask/subscriptions","organizations_url":"https://api.github.com/users/matthiask/orgs","repos_url":"https://api.github.com/users/matthiask/repos","events_url":"https://api.github.com/users/matthiask/events{/privacy}","received_events_url":"https://api.github.com/users/matthiask/received_events","type":"User","site_admin":false},"created_at":"2018-10-04T20:31:09Z","updated_at":"2018-10-04T20:31:09Z","author_association":"CONTRIBUTOR","body":"Good catch. That probably also means that the `chat_message` example I added to the docs doesn't work right now since there's no way to dispatch messages through the channel layer to the `AsyncHttpConsumer`. https://channels.readthedocs.io/en/latest/topics/consumers.html#asynchttpconsumer\r\n\r\nMaybe the code has to be changed to assemble the request body inside a new `def http_request` method which itself would call `self.handle()` as soon as the request body is complete. Also, we'd probably need a `def http_disconnect` method raising `StopConsumer` or something, and maybe also calling `self.disconnect()`\r\n\r\nI'm not working on an ASGI project right now unfortunately, so if someone else wants to pick this up -- feel free. I hope that the pointers above are helpful."}}
{"actor":{"display_login":"matthiask"}}