Skip to content

Commit

Permalink
Fix @atomic wrapper on class based views (#344)
Browse files Browse the repository at this point in the history
* Fix @atomic wrapper on class based views

* Update test_aiohttp.py

* Update aiohttp.py

* Update aiohttp.py

* Update aiohttp.py
  • Loading branch information
Dreamsorcerer authored Oct 10, 2022
1 parent 88d7f75 commit 4eb5099
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
10 changes: 6 additions & 4 deletions aiojobs/aiohttp.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions tests/test_aiohttp.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,16 @@ 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)

client = await aiohttp_client(app)
resp = await client.get("/")
assert resp.status == 200
assert await resp.text() == "GET"

scheduler = get_scheduler_from_app(app)

Expand Down

0 comments on commit 4eb5099

Please sign in to comment.