Skip to content

Commit

Permalink
Use newer APIs.
Browse files Browse the repository at this point in the history
  • Loading branch information
coleifer committed Sep 22, 2015
1 parent e8bedc0 commit db8a39f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 8 deletions.
9 changes: 3 additions & 6 deletions huey/peewee_helpers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,9 @@
def _transaction(db, fn):
@wraps(fn)
def inner(*args, **kwargs):
db.get_conn()
try:
with db.transaction():
return fn(*args, **kwargs)
finally:
db.close()
# Execute function in its own connection, in a transaction.
with db.execution_context(with_transaction=True):
return fn(*args, **kwargs)
return inner

def db_task(huey, db, *args, **kwargs):
Expand Down
4 changes: 2 additions & 2 deletions huey/tests/peewee_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def inner(*args, **kwargs):
return fn(*args, **kwargs)
return inner
connect = record_call(SqliteDatabase.connect)
close = record_call(SqliteDatabase.close)
_close = record_call(SqliteDatabase._close)
transaction = record_call(SqliteDatabase.transaction)

db = MockSqliteDatabase('test.huey.db')
Expand Down Expand Up @@ -58,5 +58,5 @@ def test_helper(self):
test_db_task('foo')
self.assertEqual(STATE, ['connect'])
huey.execute(huey.dequeue())
self.assertEqual(STATE, ['connect', 'transaction', 'create', 'close'])
self.assertEqual(STATE, ['connect', 'transaction', 'create', '_close'])
self.assertEqual(Value.select().count(), 1)

0 comments on commit db8a39f

Please sign in to comment.