]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Remove session.begin() example that was for 1.4
authorMike Bayer <mike_mp@zzzcomputing.com>
Thu, 29 Apr 2021 12:31:57 +0000 (08:31 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Thu, 29 Apr 2021 12:31:57 +0000 (08:31 -0400)
the isolation level example here was likely cherry-picked
from 1.4 ; "with session.begin()" isn't normally available
in 1.3.   will also update the 1.4 example for clarity

Change-Id: Ib86019f4b1b70392079596604ec9b0319941e4dc

doc/build/orm/session_transaction.rst

index 9afbe134a4083d180b11def77cbce7d37aeb07f9..5aaf4f2748f46486370b3ad0003a90bfbbf9163c 100644 (file)
@@ -513,12 +513,22 @@ level on a per-connection basis can be affected by using the
 
     from sqlalchemy.orm import Session
 
+    # assume session just constructed
     sess = Session(bind=engine)
-    with sess.begin():
-        sess.connection(execution_options={'isolation_level': 'SERIALIZABLE'})
 
-    # commits transaction.  the connection is released
+    # call connection() with options before any other operations proceed.
+    # this will procure a new connection from the bound engine and begin a real
+    # database transaction.
+    sess.connection(execution_options={'isolation_level': 'SERIALIZABLE'})
+
+    # ... work with session in SERIALIZABLE isolation level...
+
+    # commit transaction.  the connection is released
     # and reverted to its previous isolation level.
+    sess.commit()
+
+    # here, a new "transaction" is in play and isolation level may be set
+    # again if another transaction is to be used
 
 Above, we first produce a :class:`.Session` using either the constructor
 or a :class:`.sessionmaker`.   Then we explicitly set up the start of