changeset 31782945a446 in trytond:default
details: https://hg.tryton.org/trytond?cmd=changeset;node=31782945a446
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
diffstat:
trytond/backend/postgresql/database.py | 8 +++++++-
1 files changed, 7 insertions(+), 1 deletions(-)
diffs (22 lines):
diff -r f13813452984 -r 31782945a446 trytond/backend/postgresql/database.py
--- a/trytond/backend/postgresql/database.py Tue Jul 21 00:36:40 2020 +0200
+++ b/trytond/backend/postgresql/database.py Tue Jul 21 14:29:14 2020 +0200
@@ -221,11 +221,17 @@
logger.error(
'connection to "%s" failed', self.name, exc_info=True)
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