changeset f8cfcc8322f8 in trytond:5.0
details: https://hg.tryton.org/trytond?cmd=changeset;node=f8cfcc8322f8
description:
        Use readonly connection attribute

        It is not allowed to Call SET TRANSACTION in an AUTOCOMMIT transaction.
        It is better to set 'readonly' attribute when available and not set the
        transaction in readonly when autocommit is set.

        issue9477
        review294171002
        (grafted from 31782945a446925d9d04f059d353890aed3cc3ed)
diffstat:

 trytond/backend/postgresql/database.py |  8 +++++++-
 1 files changed, 7 insertions(+), 1 deletions(-)

diffs (22 lines):

diff -r 24b78b5a952c -r f8cfcc8322f8 trytond/backend/postgresql/database.py
--- a/trytond/backend/postgresql/database.py    Mon Jul 13 20:55:53 2020 +0200
+++ b/trytond/backend/postgresql/database.py    Tue Jul 21 14:29:14 2020 +0200
@@ -160,11 +160,17 @@
                     time.sleep(1)
                     continue
                 raise
+        # We do not use set_session because psycopg2 < 2.7 and psycopg2cffi
+        # change the default_transaction_* attributes which breaks external
+        # pooling at the transaction level.
         if autocommit:
             conn.set_isolation_level(ISOLATION_LEVEL_AUTOCOMMIT)
         else:
             conn.set_isolation_level(ISOLATION_LEVEL_REPEATABLE_READ)
-        if readonly:
+        # psycopg2cffi does not have the readonly property
+        if hasattr(conn, 'readonly'):
+            conn.readonly = readonly
+        elif not autocommit:
             cursor = conn.cursor()
             cursor.execute('SET TRANSACTION READ ONLY')
         return conn

Reply via email to