Skip to content

Commit

Permalink
Merge pull request #47 from insolite/cursor-release-on-error
Browse files Browse the repository at this point in the history
Prevent connection stuck after leaving cursor unreleased
  • Loading branch information
rudyryk committed Nov 30, 2016
2 parents 3a7eb61 + bfb63c5 commit c2236f4
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions peewee_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -575,8 +575,9 @@ def select(query):
yield from result.fetchone()
except GeneratorExit:
pass
finally:
yield from cursor.release

yield from cursor.release
return result


Expand All @@ -590,16 +591,18 @@ def insert(query):

cursor = yield from _execute_query_async(query)

if query.is_insert_returning:
if query._return_id_list:
result = map(lambda x: x[0], (yield from cursor.fetchall()))
try:
if query.is_insert_returning:
if query._return_id_list:
result = map(lambda x: x[0], (yield from cursor.fetchall()))
else:
result = (yield from cursor.fetchone())[0]
else:
result = (yield from cursor.fetchone())[0]
else:
result = yield from query.database.last_insert_id_async(
cursor, query.model_class)
result = yield from query.database.last_insert_id_async(
cursor, query.model_class)
finally:
yield from cursor.release

yield from cursor.release
return result


Expand Down

0 comments on commit c2236f4

Please sign in to comment.