Skip to content

Commit

Permalink
Remove code on sanic < 20
Browse files Browse the repository at this point in the history
  • Loading branch information
kigawas committed Mar 30, 2021
1 parent 8500d63 commit 8b27eb3
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions src/gino_sanic.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class Gino(_Gino):
pool on response. If you need to release the connection early in the middle
to do some long-running tasks, you can simply do this::
await request['connection'].release(permanent=False)
await request.ctx.connection.release(permanent=False)
"""

Expand All @@ -85,17 +85,12 @@ def init_app(self, app):
@app.middleware("request")
async def on_request(request):
conn = await self.acquire(lazy=True)
if hasattr(request, "ctx"):
request.ctx.connection = conn
else:
request["connection"] = conn
request.ctx.connection = conn

@app.middleware("response")
async def on_response(request, _):
if hasattr(request, "ctx"):
conn = getattr(request.ctx, "connection", None)
else:
conn = request.pop("connection", None)
conn = getattr(request.ctx, "connection", None)

if conn is not None:
await conn.release()

Expand Down

0 comments on commit 8b27eb3

Please sign in to comment.