]> git.ipfire.org Git - thirdparty/psycopg.git/commitdiff
More docs about Rollback usage
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>
Thu, 19 Nov 2020 03:11:17 +0000 (03:11 +0000)
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>
Thu, 19 Nov 2020 03:11:17 +0000 (03:11 +0000)
docs/connection.rst
docs/usage.rst

index abe6b08fecf60e7cf440d611457479cc35e3dcfa..84cb838b32e8ca15a10dd812eb708f50ec7aee11 100644 (file)
@@ -152,3 +152,15 @@ Connection support objects
 .. 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.
index eb45f90936fcc3f8176d5ec6bdbee20efe9e19e8..c3694f559ab5e97c4d851342ba69a00f4bbd22c2 100644 (file)
@@ -248,11 +248,13 @@ but not entirely committed yet.
 
 .. 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,