Skip to content

Commit

Permalink
add back compiler start transaction modifiers
Browse files Browse the repository at this point in the history
  • Loading branch information
fantix committed Feb 13, 2025
1 parent 98fec18 commit f2728e2
Showing 1 changed file with 32 additions and 14 deletions.
46 changes: 32 additions & 14 deletions edb/server/compiler/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
from edb.edgeql import qltypes

from edb.ir import staeval as ireval
from edb.ir import statypes
from edb.ir import ast as irast

from edb.schema import ddl as s_ddl
Expand Down Expand Up @@ -2152,22 +2153,39 @@ def _compile_ql_transaction(

ctx.state.start_tx()

sqls = 'START TRANSACTION'
# Compute the effective isolation level
iso_config: statypes.TransactionIsolation = _get_config_val(
ctx, "default_transaction_isolation"
)
default_iso = iso_config.to_qltypes()
iso = ql.isolation
if iso is not None:
if (
iso is not qltypes.TransactionIsolationLevel.SERIALIZABLE
and ql.access is not qltypes.TransactionAccessMode.READ_ONLY
):
raise errors.TransactionError(
f"{iso.value} transaction isolation level is only "
"supported in read-only transactions",
span=ql.span,
hint=f"specify READ ONLY access mode",
if iso is None:
iso = default_iso

# Compute the effective access mode
access = ql.access
if access is None:
if default_iso is qltypes.TransactionIsolationLevel.SERIALIZABLE:
access_mode: statypes.TransactionAccessMode = _get_config_val(
ctx, "default_transaction_access_mode"
)
sqls += f' ISOLATION LEVEL {iso.value}'
if ql.access is not None:
sqls += f' {ql.access.value}'
access = access_mode.to_qltypes()
else:
access = qltypes.TransactionAccessMode.READ_ONLY

# Guard against unsupported isolation + access combinations
if (
iso is not qltypes.TransactionIsolationLevel.SERIALIZABLE
and access is not qltypes.TransactionAccessMode.READ_ONLY
):
raise errors.TransactionError(
f"{iso.value} transaction isolation level is only "
"supported in read-only transactions",
span=ql.span,
hint=f"specify READ ONLY access mode",
)

sqls = f'START TRANSACTION ISOLATION LEVEL {iso.value} {access.value}'
if ql.deferrable is not None:
sqls += f' {ql.deferrable.value}'
sqls += ';'
Expand Down

0 comments on commit f2728e2

Please sign in to comment.