diff --git a/edb/ir/statypes.py b/edb/ir/statypes.py index 8c834d7622bb..09f122161e97 100644 --- a/edb/ir/statypes.py +++ b/edb/ir/statypes.py @@ -801,3 +801,13 @@ def get_translation_map(cls) -> Mapping[TransactionIsolationEnum, str]: TransactionIsolationEnum.Serializable: "serializable", TransactionIsolationEnum.RepeatableRead: "repeatable read", } + + def to_qltypes(self) -> qltypes.TransactionIsolationLevel: + from edb.edgeql import qltypes + match self._val: + case TransactionIsolationEnum.Serializable: + return qltypes.TransactionIsolationLevel.SERIALIZABLE + case TransactionIsolationEnum.RepeatableRead: + return qltypes.TransactionIsolationLevel.REPEATABLE_READ + case _: + raise AssertionError(f"unexpected value: {self._val!r}") diff --git a/edb/lib/cfg.edgeql b/edb/lib/cfg.edgeql index a60eac426bb5..bf8cb298c1f6 100644 --- a/edb/lib/cfg.edgeql +++ b/edb/lib/cfg.edgeql @@ -191,6 +191,7 @@ ALTER TYPE cfg::AbstractConfig { CREATE REQUIRED PROPERTY default_transaction_isolation -> sys::TransactionIsolation { + CREATE ANNOTATION cfg::affects_compilation := 'true'; CREATE ANNOTATION cfg::backend_setting := '"default_transaction_isolation"'; CREATE ANNOTATION std::description := diff --git a/edb/server/compiler/compiler.py b/edb/server/compiler/compiler.py index 9b51c86f87d3..5e779e2e2298 100644 --- a/edb/server/compiler/compiler.py +++ b/edb/server/compiler/compiler.py @@ -2167,7 +2167,14 @@ def _compile_ql_transaction( hint=f"specify READ ONLY access mode", ) sqls += f' ISOLATION LEVEL {iso.value}' - if ql.access is None: + else: + iso_config: statypes.TransactionIsolation = _get_config_val( + ctx, "default_transaction_isolation" + ) + iso = iso_config.to_qltypes() + if iso is not qltypes.TransactionIsolationLevel.SERIALIZABLE: + sqls += f' {qltypes.TransactionAccessMode.READ_ONLY.value}' + elif ql.access is None: access_mode: statypes.TransactionAccessMode = _get_config_val( ctx, "default_transaction_access_mode" )