for command in self._get_commit_commands():
yield from self._conn._exec_command(command)
+ if self._conn._pipeline:
+ yield from self._conn._pipeline._sync_gen()
+
def _rollback_gen(self, exc_val: Optional[BaseException]) -> PQGen[bool]:
if isinstance(exc_val, Rollback):
logger.debug(f"{self._conn}: Explicit rollback from: ", exc_info=True)
conn.execute("select 1 from nosuchtable")
with pytest.raises(e.UndefinedTable):
conn.commit()
- conn.rollback()
+ conn.rollback() # TODO: inconsistent with non-pipeline.
+ cur1 = conn.execute("select 1")
+ cur2 = conn.execute("select 2")
+
+ assert cur1.fetchone() == (1,)
+ assert cur2.fetchone() == (2,)
+
+
+def test_errors_raised_on_transaction_exit(conn):
+ here = False
+ with conn.pipeline():
+ with pytest.raises(e.UndefinedTable):
+ with conn.transaction():
+ conn.execute("select 1 from nosuchtable")
+ here = True
+ conn.rollback() # TODO: inconsistent with non-pipeline.
+ cur1 = conn.execute("select 1")
+ assert here
+ cur2 = conn.execute("select 2")
+
+ assert cur1.fetchone() == (1,)
+ assert cur2.fetchone() == (2,)
+
+
+def test_errors_raised_on_nested_transaction_exit(conn):
+ here = False
+ with conn.pipeline():
+ with pytest.raises(e.UndefinedTable):
+ with conn.transaction():
+ with conn.transaction():
+ conn.execute("select 1 from nosuchtable")
+ here = True
+ conn.rollback() # TODO: inconsistent with non-pipeline.
cur1 = conn.execute("select 1")
+ assert here
cur2 = conn.execute("select 2")
assert cur1.fetchone() == (1,)
await aconn.execute("select 1 from nosuchtable")
with pytest.raises(e.UndefinedTable):
await aconn.commit()
- await aconn.rollback()
+ await aconn.rollback() # TODO: inconsistent with non-pipeline.
+ cur1 = await aconn.execute("select 1")
+ cur2 = await aconn.execute("select 2")
+
+ assert await cur1.fetchone() == (1,)
+ assert await cur2.fetchone() == (2,)
+
+
+async def test_errors_raised_on_transaction_exit(aconn):
+ here = False
+ async with aconn.pipeline():
+ with pytest.raises(e.UndefinedTable):
+ async with aconn.transaction():
+ await aconn.execute("select 1 from nosuchtable")
+ here = True
+ await aconn.rollback() # TODO: inconsistent with non-pipeline.
+ cur1 = await aconn.execute("select 1")
+ assert here
+ cur2 = await aconn.execute("select 2")
+
+ assert await cur1.fetchone() == (1,)
+ assert await cur2.fetchone() == (2,)
+
+
+async def test_errors_raised_on_nested_transaction_exit(aconn):
+ here = False
+ async with aconn.pipeline():
+ with pytest.raises(e.UndefinedTable):
+ async with aconn.transaction():
+ async with aconn.transaction():
+ await aconn.execute("select 1 from nosuchtable")
+ here = True
+ await aconn.rollback() # TODO: inconsistent with non-pipeline.
cur1 = await aconn.execute("select 1")
+ assert here
cur2 = await aconn.execute("select 2")
assert await cur1.fetchone() == (1,)