{"action":"created","issue":{"url":"https://api.github.com/repos/housleyjk/aiopyramid/issues/24","repository_url":"https://api.github.com/repos/housleyjk/aiopyramid","labels_url":"https://api.github.com/repos/housleyjk/aiopyramid/issues/24/labels{/name}","comments_url":"https://api.github.com/repos/housleyjk/aiopyramid/issues/24/comments","events_url":"https://api.github.com/repos/housleyjk/aiopyramid/issues/24/events","html_url":"https://github.com/housleyjk/aiopyramid/issues/24","id":181528681,"number":24,"title":"add_request_method with async function","user":{"login":"dfee","id":262602,"avatar_url":"https://avatars.githubusercontent.com/u/262602?v=3","gravatar_id":"","url":"https://api.github.com/users/dfee","html_url":"https://github.com/dfee","followers_url":"https://api.github.com/users/dfee/followers","following_url":"https://api.github.com/users/dfee/following{/other_user}","gists_url":"https://api.github.com/users/dfee/gists{/gist_id}","starred_url":"https://api.github.com/users/dfee/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dfee/subscriptions","organizations_url":"https://api.github.com/users/dfee/orgs","repos_url":"https://api.github.com/users/dfee/repos","events_url":"https://api.github.com/users/dfee/events{/privacy}","received_events_url":"https://api.github.com/users/dfee/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2016-10-06T21:20:23Z","updated_at":"2016-10-13T09:06:18Z","closed_at":"2016-10-13T09:06:18Z","body":"Elsewhere, I'd asked about using `add_request_method` with asyncio-redis. The solution there was to pull asyncio-redis out and instantiate the pool upon app initialization.\r\n\r\nHowever, when doing something like adding a `user` attribute to a request method, we run into some interesting challenges (problems). Consider the following code:\r\n\r\n```\r\n@use_executor\r\ndef load_user(request, _id):\r\n    if not _id:\r\n        return None\r\n    return User.by_short_id(_id, request.db)\r\n\r\nasync def get_user(request):\r\n    _id = await request.unauthenticated_userid\r\n    if not _id:\r\n        return\r\n    return await User.by_short_id(_id, request.db)\r\n\r\ndef includeme(config):\r\n    config.add_request_method(get_user, 'user', reify=True)\r\n```\r\n\r\nIn view code, we'll want to get the user like so:\r\n```\r\nasync def my_view(request):\r\n    await request.user  # success\r\n    await request.user  # RuntimeError: cannot reuse already awaited coroutine.\r\n```\r\n\r\nI'm not quite able to figure out how to navigate around this problem. Ideally, I'd have a solution that didn't require `await request.user`, but behind the scenes, there is still await code doing what `get_user` is doing above. Any ideas?"},"comment":{"url":"https://api.github.com/repos/housleyjk/aiopyramid/issues/comments/253457375","html_url":"https://github.com/housleyjk/aiopyramid/issues/24#issuecomment-253457375","issue_url":"https://api.github.com/repos/housleyjk/aiopyramid/issues/24","id":253457375,"user":{"login":"dfee","id":262602,"avatar_url":"https://avatars.githubusercontent.com/u/262602?v=3","gravatar_id":"","url":"https://api.github.com/users/dfee","html_url":"https://github.com/dfee","followers_url":"https://api.github.com/users/dfee/followers","following_url":"https://api.github.com/users/dfee/following{/other_user}","gists_url":"https://api.github.com/users/dfee/gists{/gist_id}","starred_url":"https://api.github.com/users/dfee/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dfee/subscriptions","organizations_url":"https://api.github.com/users/dfee/orgs","repos_url":"https://api.github.com/users/dfee/repos","events_url":"https://api.github.com/users/dfee/events{/privacy}","received_events_url":"https://api.github.com/users/dfee/received_events","type":"User","site_admin":false},"created_at":"2016-10-13T09:06:18Z","updated_at":"2016-10-13T09:06:18Z","body":"Moved away from `asyncio-redis`. This question is no longer relevant for me."}}
{"actor":{"display_login":"dfee"}}