Skip to content

Commit

Permalink
Fix a bug for processing transactions in line.
Browse files Browse the repository at this point in the history
  • Loading branch information
asvetlov committed Oct 31, 2014
1 parent ba3886c commit fab8bb4
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
5 changes: 5 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
CHANGES
-------

0.5.1 (2014-10-31)
^^^^^^^^^^^^^^^^^^

* Fix a bug for processing transactions in line.

0.5.0 (2014-10-31)
^^^^^^^^^^^^^^^^^^

Expand Down
1 change: 1 addition & 0 deletions aiopg/sa/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ def _commit_impl(self):
yield from cur.execute('COMMIT')
finally:
cur.close()
self._transaction = None

@asyncio.coroutine
def _rollback_impl(self):
Expand Down
29 changes: 29 additions & 0 deletions tests/test_sa_transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -390,3 +390,32 @@ def go():
yield from tr.commit()

self.loop.run_until_complete(go())

def test_transactions_sequence(self):
@asyncio.coroutine
def go():
conn = yield from self.connect()

yield from conn.execute(tbl.delete())

self.assertIsNone(conn._transaction)

tr1 = yield from conn.begin()
self.assertIs(tr1, conn._transaction)
yield from conn.execute(tbl.insert().values(name='a'))
res1 = yield from conn.scalar(tbl.count())
self.assertEqual(1, res1)

yield from tr1.commit()
self.assertIsNone(conn._transaction)

tr2 = yield from conn.begin()
self.assertIs(tr2, conn._transaction)
yield from conn.execute(tbl.insert().values(name='b'))
res2 = yield from conn.scalar(tbl.count())
self.assertEqual(2, res2)

yield from tr2.commit()
self.assertIsNone(conn._transaction)

self.loop.run_until_complete(go())

1 comment on commit fab8bb4

@fantix
Copy link
Contributor

@fantix fantix commented on fab8bb4 Oct 23, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be applied for _rollback_impl as well?

Please sign in to comment.