Skip to content

Commit 00d5de2

Browse files
authored
Merge pull request #533 from qulaz/master
Fixes #532, fix releasing connection after exception in Starlette extension
2 parents f8b39f7 + 3032d29 commit 00d5de2

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

gino/ext/starlette.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,12 @@ async def __call__(self, scope: Scope, receive: Receive,
7171
if (scope['type'] == 'http' and
7272
self.db.config['use_connection_for_request']):
7373
scope['connection'] = await self.db.acquire(lazy=True)
74-
await self.app(scope, receive, send)
75-
conn = scope.pop('connection', None)
76-
if conn is not None:
77-
await conn.release()
74+
try:
75+
await self.app(scope, receive, send)
76+
finally:
77+
conn = scope.pop('connection', None)
78+
if conn is not None:
79+
await conn.release()
7880
return
7981

8082
if scope['type'] == 'lifespan':

0 commit comments

Comments
 (0)