.. autoclass:: AsyncTransaction(connection: AsyncConnection, savepoint_name: Optional[str] = None, force_rollback: bool = False)
.. autoexception:: Rollback
+
+ It can be used as
+
+ - ``raise Rollback``: roll back the operation that happened in the current
+ transaction block and continue the program after the block.
+
+ - ``raise Rollback()``: same effect as above
+
+ - :samp:`raise Rollback({tx})`: roll back any operation that happened in
+ the `Transaction` *tx* (returned by a statement such as :samp:`with
+ conn.transaction() as {tx}:` and all the blocks nested within. The
+ program will continue after the *tx* block.
.. code:: python
+ from psycopg3 import Rollback
+
with conn.transaction() as outer_tx:
for command in commands():
with conn.transaction() as inner_tx:
if isinstance(command, CancelCommand):
- raise psycopg3.Rollback(outer_tx)
+ raise Rollback(outer_tx)
process_command(command)
# If `Rollback` is raised, it would propagate only up to this block,