return f"{self.__class__.__qualname__}({', '.join(args)})"
def _enter_commands(self) -> List[str]:
- assert self._yolo
- self._yolo = False
+ if not self._yolo:
+ raise TypeError("transaction blocks cannot be use more than once")
+ else:
+ self._yolo = False
self._outer_transaction = (
self._conn.pgconn.transaction_status == TransactionStatus.IDLE
tx.savepoint_name = "bar"
+def test_cant_reenter(conn):
+ with conn.transaction() as tx:
+ pass
+
+ with pytest.raises(TypeError):
+ with tx:
+ pass
+
+
def test_begins_on_enter(conn):
"""Transaction does not begin until __enter__() is called."""
tx = conn.transaction()
tx.savepoint_name = "bar"
+async def test_cant_reenter(aconn):
+ async with aconn.transaction() as tx:
+ pass
+
+ with pytest.raises(TypeError):
+ async with tx:
+ pass
+
+
async def test_begins_on_enter(aconn):
"""Transaction does not begin until __enter__() is called."""
tx = aconn.transaction()