Skip to content

Commit 553e3ce

Browse files
authored
Make TransactionOptions default to optional (#612)
Visible behavior should be the same for now. Later, once we support putting the TransactionOptions values into config, it will be important to distinguish whether they are actually set.
1 parent 7d2a401 commit 553e3ce

File tree

1 file changed

+24
-15
lines changed

1 file changed

+24
-15
lines changed

gel/options.py

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,9 @@ class TransactionOptions:
115115

116116
def __init__(
117117
self,
118-
isolation: IsolationLevel=IsolationLevel.Serializable,
119-
readonly: bool = False,
120-
deferrable: bool = False,
118+
isolation: typing.Optional[IsolationLevel] = None,
119+
readonly: typing.Optional[bool] = None,
120+
deferrable: typing.Optional[bool] = None,
121121
):
122122
self._isolation = isolation
123123
self._readonly = readonly
@@ -128,18 +128,27 @@ def defaults(cls):
128128
return cls()
129129

130130
def start_transaction_query(self):
131-
isolation = IsolationLevel._to_start_tx_str(self._isolation)
132-
if self._readonly:
133-
mode = 'READ ONLY'
134-
else:
135-
mode = 'READ WRITE'
136-
137-
if self._deferrable:
138-
defer = 'DEFERRABLE'
139-
else:
140-
defer = 'NOT DEFERRABLE'
141-
142-
return f'START TRANSACTION ISOLATION {isolation}, {mode}, {defer};'
131+
options = []
132+
if self._isolation is not None:
133+
level = IsolationLevel._to_start_tx_str(self._isolation)
134+
options.append(f'ISOLATION {level}')
135+
136+
if self._readonly is not None:
137+
if self._readonly:
138+
mode = 'READ ONLY'
139+
else:
140+
mode = 'READ WRITE'
141+
options.append(mode)
142+
143+
if self._deferrable is not None:
144+
if self._deferrable:
145+
defer = 'DEFERRABLE'
146+
else:
147+
defer = 'NOT DEFERRABLE'
148+
options.append(defer)
149+
150+
opt_str = ', '.join(options)
151+
return f'START TRANSACTION {opt_str};'
143152

144153
def __repr__(self):
145154
return (

0 commit comments

Comments
 (0)