def set_transaction_isolation_level(session, sqla_txn, connection):
''' Set appropriate transaction isolation level.
Doomed transactions can be read-only.
``transaction.doom()`` must be called before the connection is used.
Othewise assume it is a write which must be REPEATABLE READ.
'''
if connection.engine.url.drivername != 'postgresql':
return
txn = transaction.get()
if not txn.isDoomed():
# connection.execute("SET TRANSACTION ISOLATION LEVEL REPEATABLE READ;")
return
data = txn._extension
if 'snapshot_id' in data:
connection.execute(
_set_transaction_snapshot,
snapshot_id=data['snapshot_id'])
else:
connection.execute("SET TRANSACTION READ ONLY;")
评论列表
文章目录