@@ -334,8 +334,9 @@ def fetchone(self):
334334 except StopIteration :
335335 return
336336 except Aborted :
337- self .connection .retry_transaction ()
338- return self .fetchone ()
337+ if not self .connection .read_only :
338+ self .connection .retry_transaction ()
339+ return self .fetchone ()
339340
340341 def fetchall (self ):
341342 """Fetch all (remaining) rows of a query result, returning them as
@@ -350,8 +351,9 @@ def fetchall(self):
350351 self ._checksum .consume_result (row )
351352 res .append (row )
352353 except Aborted :
353- self .connection .retry_transaction ()
354- return self .fetchall ()
354+ if not self .connection .read_only :
355+ self .connection .retry_transaction ()
356+ return self .fetchall ()
355357
356358 return res
357359
@@ -381,8 +383,9 @@ def fetchmany(self, size=None):
381383 except StopIteration :
382384 break
383385 except Aborted :
384- self .connection .retry_transaction ()
385- return self .fetchmany (size )
386+ if not self .connection .read_only :
387+ self .connection .retry_transaction ()
388+ return self .fetchmany (size )
386389
387390 return items
388391
@@ -405,30 +408,21 @@ def _handle_DQL_with_snapshot(self, snapshot, sql, params):
405408 res = snapshot .execute_sql (
406409 sql , params = params , param_types = get_param_types (params )
407410 )
408- if type (res ) == int :
409- self ._row_count = res
410- self ._itr = None
411- else :
412- # Immediately using:
413- # iter(response)
414- # here, because this Spanner API doesn't provide
415- # easy mechanisms to detect when only a single item
416- # is returned or many, yet mixing results that
417- # are for .fetchone() with those that would result in
418- # many items returns a RuntimeError if .fetchone() is
419- # invoked and vice versa.
420- self ._result_set = res
421- # Read the first element so that the StreamedResultSet can
422- # return the metadata after a DQL statement. See issue #155.
423- while True :
424- try :
425- self ._itr = PeekIterator (self ._result_set )
426- break
427- except Aborted :
428- self .connection .retry_transaction ()
429- # Unfortunately, Spanner doesn't seem to send back
430- # information about the number of rows available.
431- self ._row_count = _UNSET_COUNT
411+ # Immediately using:
412+ # iter(response)
413+ # here, because this Spanner API doesn't provide
414+ # easy mechanisms to detect when only a single item
415+ # is returned or many, yet mixing results that
416+ # are for .fetchone() with those that would result in
417+ # many items returns a RuntimeError if .fetchone() is
418+ # invoked and vice versa.
419+ self ._result_set = res
420+ # Read the first element so that the StreamedResultSet can
421+ # return the metadata after a DQL statement. See issue #155.
422+ self ._itr = PeekIterator (self ._result_set )
423+ # Unfortunately, Spanner doesn't seem to send back
424+ # information about the number of rows available.
425+ self ._row_count = _UNSET_COUNT
432426
433427 def _handle_DQL (self , sql , params ):
434428 if self .connection .read_only and not self .connection .autocommit :
0 commit comments