diff --git a/aiojobs/aiohttp.py b/aiojobs/aiohttp.py index 744da73f..4d0d598b 100644 --- a/aiojobs/aiohttp.py +++ b/aiojobs/aiohttp.py @@ -28,12 +28,14 @@ async def spawn(request, coro): def atomic(coro): @wraps(coro) - async def wrapper(request): - if isinstance(request, View): + async def wrapper(request_or_view): + if isinstance(request_or_view, View): # Class Based View decorated. - request = request.request + request = request_or_view.request + else: + request = request_or_view - job = await spawn(request, coro(request)) + job = await spawn(request, coro(request_or_view)) return await job.wait() return wrapper diff --git a/tests/test_aiohttp.py b/tests/test_aiohttp.py index 09d589c9..97c5bf6f 100644 --- a/tests/test_aiohttp.py +++ b/tests/test_aiohttp.py @@ -82,8 +82,8 @@ async def test_atomic_from_view(aiohttp_client): class MyView(web.View): @atomic - async def get(self): - return web.Response() + async def get(self) -> web.Response: + return web.Response(text=self.request.method) app.router.add_route("*", "/", MyView) aiojobs_setup(app) @@ -91,6 +91,7 @@ async def get(self): client = await aiohttp_client(app) resp = await client.get("/") assert resp.status == 200 + assert await resp.text() == "GET" scheduler = get_scheduler_from_app(app)