@@ -71,16 +71,8 @@ def get_retry_settings(indexed_function):
7171
7272
7373def build_fixed_delay_retry (protos , retry , max_retry_count , retry_strategy ):
74- try :
75- from google .protobuf .duration_pb2 import Duration
76- except ImportError :
77- raise ImportError (
78- "protobuf not found when trying to "
79- "import Duration."
80- "Sys Path: %s. "
81- "Sys Modules: %s. " ,
82- sys .path , sys .modules )
83- delay_interval = Duration (
74+ # In protobuf 5.x, Duration fields expect timedelta objects, not Duration objects
75+ delay_interval = timedelta (
8476 seconds = convert_to_seconds (retry .get (RetryPolicy .DELAY_INTERVAL .value ))
8577 )
8678 return protos .RpcRetryOptions (
@@ -91,15 +83,15 @@ def build_fixed_delay_retry(protos, retry, max_retry_count, retry_strategy):
9183
9284
9385def build_variable_interval_retry (protos , retry , max_retry_count , retry_strategy ):
94- # Get minimum_interval with default of 00:00:00 (0 seconds)
95- min_interval_str = retry . get ( RetryPolicy . MINIMUM_INTERVAL . value )
96- min_seconds = convert_to_seconds ( min_interval_str ) if min_interval_str else 0
97- minimum_interval = timedelta ( seconds = min_seconds )
98-
99- # Get maximum_interval with default of TimeSpan.MaxValue equivalent (max int32 seconds)
100- max_interval_str = retry . get ( RetryPolicy . MAXIMUM_INTERVAL . value )
101- max_seconds = convert_to_seconds ( max_interval_str ) if max_interval_str else 2147483647
102- maximum_interval = timedelta ( seconds = max_seconds )
86+ # In protobuf 5.x, Duration fields expect timedelta objects, not Duration objects
87+ minimum_interval = timedelta (
88+ seconds = convert_to_seconds (
89+ retry . get ( RetryPolicy . MINIMUM_INTERVAL . value ) )
90+ )
91+ maximum_interval = timedelta (
92+ seconds = convert_to_seconds (
93+ retry . get ( RetryPolicy . MAXIMUM_INTERVAL . value ))
94+ )
10395
10496 return protos .RpcRetryOptions (
10597 max_retry_count = max_retry_count ,
0 commit comments