]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Add close_with_result to pessimistic connection example
authorMike Bayer <mike_mp@zzzcomputing.com>
Thu, 12 May 2016 11:54:14 +0000 (07:54 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Thu, 12 May 2016 11:54:14 +0000 (07:54 -0400)
For connectionless execution, the recipe here will fail unless
the should_close_with_result flag is temporarily set to False.

Change-Id: Ib77b4439e8361b24478108c413b1ba720a68350f
Fixes: #3712
doc/build/core/pooling.rst

index 2855d1a9525ca88832c9a3689dd48c2d1a72b502..65b5ca9cd084ccafe318fd7ddcf046d94d5a1214 100644 (file)
@@ -253,6 +253,11 @@ best way to do this is to make use of the
             # we don't want to bother pinging on these.
             return
 
+        # turn off "close with result".  This flag is only used with
+        # "connectionless" execution, otherwise will be False in any case
+        save_should_close_with_result = connection.should_close_with_result
+        connection.should_close_with_result = False
+
         try:
             # run a SELECT 1.   use a core select() so that
             # the SELECT of a scalar value without a table is
@@ -272,6 +277,9 @@ best way to do this is to make use of the
                 connection.scalar(select([1]))
             else:
                 raise
+        finally:
+            # restore "close with result"
+            connection.should_close_with_result = save_should_close_with_result
 
 The above recipe has the advantage that we are making use of SQLAlchemy's
 facilities for detecting those DBAPI exceptions that are known to indicate