Skip to content

Commit

Permalink
Run queries within peewee exception_wrapper() context, so exceptions …
Browse files Browse the repository at this point in the history
…raised are now same as for sync execution
  • Loading branch information
rudyryk committed Apr 20, 2016
1 parent 1d644d4 commit fd50739
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
5 changes: 3 additions & 2 deletions peewee_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ def create_or_get(self, model, **kwargs):
"""
try:
return (yield from self.create(model, **kwargs)), True
except: # except peewee.IntegrityError:
except peewee.IntegrityError:
query = []
for field_name, value in kwargs.items():
field = getattr(model, field_name)
Expand Down Expand Up @@ -1394,4 +1394,5 @@ def _run_sql(db, operation, *args, **kwargs):
def _execute_query_async(query):
"""Execute query and return cursor object.
"""
return (yield from _run_sql(query.database, *query.sql()))
with query.database.exception_wrapper():
return (yield from _run_sql(query.database, *query.sql()))
2 changes: 1 addition & 1 deletion tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ def test_connect_close(self):
@asyncio.coroutine
def get_conn(objects):
yield from objects.connect()
yield from asyncio.sleep(0.125, loop=self.loop)
# yield from asyncio.sleep(0.05, loop=self.loop)
# NOTE: "private" member access
return objects.database._async_conn

Expand Down

0 comments on commit fd50739

Please sign in to comment.