@@ -399,35 +399,32 @@ def _exc_to_status(exc: BaseException) -> StatusCode:
399399 return exc .code ()
400400 return StatusCode .UNKNOWN
401401
402- def track_retryable_error (self ) -> callable [[ Exception ], None ] :
402+ def track_retryable_error (self , exc : Exception ) -> None :
403403 """
404404 Used as input to api_core.Retry classes, to track when retryable errors are encountered
405405
406406 Should be passed as on_error callback
407407 """
408-
409- def wrapper (exc : Exception ) -> None :
410- try :
411- # record metadata from failed rpc
412- if (
413- isinstance (exc , GoogleAPICallError )
414- and exc .errors
415- ):
416- rpc_error = exc .errors [- 1 ]
417- metadata = list (rpc_error .trailing_metadata ()) + list (
418- rpc_error .initial_metadata ()
419- )
420- self .add_response_metadata ({k : v for k , v in metadata })
421- except Exception :
422- # ignore errors in metadata collection
423- pass
424- if isinstance (exc , _MutateRowsIncomplete ):
425- # _MutateRowsIncomplete represents a successful rpc with some failed mutations
426- # mark the attempt as successful
427- self .end_attempt_with_status (StatusCode .OK )
428- else :
429- self .end_attempt_with_status (exc )
430- return wrapper
408+ try :
409+ # record metadata from failed rpc
410+ if (
411+ isinstance (exc , GoogleAPICallError )
412+ and exc .errors
413+ ):
414+ rpc_error = exc .errors [- 1 ]
415+ metadata = list (rpc_error .trailing_metadata ()) + list (
416+ rpc_error .initial_metadata ()
417+ )
418+ self .add_response_metadata ({k : v for k , v in metadata })
419+ except Exception :
420+ # ignore errors in metadata collection
421+ pass
422+ if isinstance (exc , _MutateRowsIncomplete ):
423+ # _MutateRowsIncomplete represents a successful rpc with some failed mutations
424+ # mark the attempt as successful
425+ self .end_attempt_with_status (StatusCode .OK )
426+ else :
427+ self .end_attempt_with_status (exc )
431428
432429 def track_terminal_error (self , exception_factory :callable [
433430 [list [Exception ], RetryFailureReason , float | None ],tuple [Exception , Exception | None ],
@@ -458,7 +455,7 @@ def wrapper(
458455 if reason == RetryFailureReason .TIMEOUT and self .state == OperationState .ACTIVE_ATTEMPT and exc_list :
459456 # record ending attempt for timeout failures
460457 attempt_exc = exc_list [- 1 ]
461- self .track_retryable_error ()( attempt_exc )
458+ self .track_retryable_error (attempt_exc )
462459 self .end_with_status (source_exc )
463460 return source_exc , cause_exc
464461 return wrapper
0 commit comments