@@ -46,17 +46,6 @@ def __init__(self, connection, isolation, readonly, deferrable):
4646 'isolation is expected to be either of {}, '
4747 'got {!r}' .format (ISOLATION_LEVELS , isolation ))
4848
49- if isolation and isolation != 'serializable' :
50- if readonly :
51- raise ValueError (
52- '"readonly" is only supported for '
53- 'serializable transactions' )
54-
55- if deferrable and not readonly :
56- raise ValueError (
57- '"deferrable" is only supported for '
58- 'serializable readonly transactions' )
59-
6049 self ._isolation = isolation
6150 self ._readonly = readonly
6251 self ._deferrable = deferrable
@@ -132,19 +121,18 @@ async def start(self):
132121 self ._id = con ._get_unique_id ('savepoint' )
133122 query = 'SAVEPOINT {};' .format (self ._id )
134123 else :
135- if self ._isolation is None :
136- query = 'BEGIN;'
137- elif self ._isolation == 'read_committed' :
138- query = 'BEGIN ISOLATION LEVEL READ COMMITTED;'
124+ query = 'BEGIN'
125+ if self ._isolation == 'read_committed' :
126+ query += ' ISOLATION LEVEL READ COMMITTED'
139127 elif self ._isolation == 'repeatable_read' :
140- query = 'BEGIN ISOLATION LEVEL REPEATABLE READ; '
141- else :
142- query = 'BEGIN ISOLATION LEVEL SERIALIZABLE'
143- if self ._readonly :
144- query += ' READ ONLY'
145- if self ._deferrable :
146- query += ' DEFERRABLE'
147- query += ';'
128+ query + = ' ISOLATION LEVEL REPEATABLE READ'
129+ elif self . _isolation == 'serializable' :
130+ query + = ' ISOLATION LEVEL SERIALIZABLE'
131+ if self ._readonly :
132+ query += ' READ ONLY'
133+ if self ._deferrable :
134+ query += ' DEFERRABLE'
135+ query += ';'
148136
149137 try :
150138 await self ._connection .execute (query )
0 commit comments