Skip to content

Commit 7d2a401

Browse files
authored
Make IsolationLevel enum values match the server names (#611)
This will let them be passed to the server.
1 parent 87d6f4c commit 7d2a401

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

gel/_testbase.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,10 @@ def tearDown(self):
507507
self.client.execute(self.TEARDOWN_METHOD))
508508
finally:
509509
try:
510-
if self.client.connection.is_in_transaction():
510+
if (
511+
self.client.connection
512+
and self.client.connection.is_in_transaction()
513+
):
511514
raise AssertionError(
512515
'test connection is still in transaction '
513516
'*after* the test')

gel/options.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,19 @@ class RetryCondition:
5252

5353
class IsolationLevel:
5454
"""Isolation level for transaction"""
55-
Serializable = "SERIALIZABLE"
56-
RepeatableRead = "REPEATABLE READ"
57-
55+
Serializable = "Serializable"
56+
RepeatableRead = "RepeatableRead"
57+
58+
@staticmethod
59+
def _to_start_tx_str(v):
60+
if v == IsolationLevel.Serializable:
61+
return 'SERIALIZABLE'
62+
elif v == IsolationLevel.RepeatableRead:
63+
return 'REPEATABLE READ'
64+
else:
65+
raise ValueError(
66+
f"Invalid isolation_level value for transaction(): {self}"
67+
)
5868

5969
class RetryOptions:
6070
"""An immutable class that contains rules for `transaction()`"""
@@ -118,7 +128,7 @@ def defaults(cls):
118128
return cls()
119129

120130
def start_transaction_query(self):
121-
isolation = str(self._isolation)
131+
isolation = IsolationLevel._to_start_tx_str(self._isolation)
122132
if self._readonly:
123133
mode = 'READ ONLY'
124134
else:

0 commit comments

Comments
 (0)