Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion asyncpg/cursor.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def _check_ready(self):
raise exceptions.InterfaceError(
'cursor: the prepared statement is closed')

if not self._connection._top_xact:
if not self._connection.is_in_transaction():
raise exceptions.NoActiveSQLTransactionError(
'cursor cannot be created outside of a transaction')

Expand Down
11 changes: 11 additions & 0 deletions tests/test_cursor.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,17 @@ async def test_cursor_01(self):
'cursor cannot be created.*transaction'):
await st.cursor()

async def test_cursor_external_transaction(self):
await self.con.execute('BEGIN')
try:
st = await self.con.prepare('SELECT generate_series(0, 2)')
cur = await st.cursor()
self.assertEqual(
await cur.fetch(10),
[(0,), (1,), (2,)])
finally:
await self.con.execute('ROLLBACK')

async def test_cursor_02(self):
st = await self.con.prepare('SELECT generate_series(0, 20)')
async with self.con.transaction():
Expand Down