Skip to content

Commit

Permalink
Move exception_wrapper() context to _run_sql()
Browse files Browse the repository at this point in the history
  • Loading branch information
rudyryk committed Apr 20, 2016
1 parent fd50739 commit 569eba3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
- Add high-level API via Manager class
- Add support for MySQL
- Auto-connect is performed for async queries if database is initialized, so no need to call `connect_async()` manually! And no worries, nothing will happen on duplicate calls
- Run SQL within `peewee.Database.exception_wrapper()` context, the same way as for sync requests

## 0.4.1

Expand Down
20 changes: 10 additions & 10 deletions peewee_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -1376,23 +1376,23 @@ def __aexit__(self, exc_type, exc_val, exc_tb):


@asyncio.coroutine
def _run_sql(db, operation, *args, **kwargs):
def _run_sql(database, operation, *args, **kwargs):
"""Run SQL operation (query or command) against database.
"""
cursor = yield from db.cursor_async()
with database.exception_wrapper():
cursor = yield from database.cursor_async()

try:
yield from cursor.execute(operation, *args, **kwargs)
except:
cursor.release()
raise
try:
yield from cursor.execute(operation, *args, **kwargs)
except:
cursor.release()
raise

return cursor
return cursor


@asyncio.coroutine
def _execute_query_async(query):
"""Execute query and return cursor object.
"""
with query.database.exception_wrapper():
return (yield from _run_sql(query.database, *query.sql()))
return (yield from _run_sql(query.database, *query.sql()))

0 comments on commit 569eba3

Please sign in to comment.