Skip to content

Commit 5c1652d

Browse files
vam-googleparthea
andauthored
fix: Fix timeout default values (#1480)
* fix: Fix timeout default values Also fix LRO for REST transport. This PR makes generated gapics appeciate timeout values from grpc_service_config.json instead of overriding them with None (which means no timeout) It is basically a direct fix for googleapis/gapic-generator-python#1477. This PR depends on googleapis/python-api-core#462, and expects `setup.py.j2` templates to be updated after googleapis/python-api-core#462 gets pushed and released with new version. * rename uri_prefix to path_prefix to match corresponding python-api-core change * fix unnecessary `gapic_v1.method.DEFAULT` in rest stubs * fix(deps): require google-api-core >=1.34.0 * fix(deps): require google-api-core >=2.11.0 * revert changes to WORKSPACE * fix typo * fix mypy error * revert local change for debugging Co-authored-by: Anthonios Partheniou <partheniou@google.com>
1 parent 7cfcf74 commit 5c1652d

File tree

56 files changed

+445
-406
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+445
-406
lines changed

packages/gapic-generator/gapic/ads-templates/%namespace/%name/%version/%sub/services/%service/_mixins.py.j2

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
request: Optional[operations_pb2.ListOperationsRequest] = None,
77
*,
88
retry: OptionalRetry = gapic_v1.method.DEFAULT,
9-
timeout: Optional[float] = None,
9+
timeout: Union[float, object] = gapic_v1.method.DEFAULT,
1010
metadata: Sequence[Tuple[str, str]] = (),
1111
) -> operations_pb2.ListOperationsResponse:
1212
r"""Lists operations that match the specified filter in the request.
@@ -60,7 +60,7 @@
6060
request: Optional[operations_pb2.GetOperationRequest] = None,
6161
*,
6262
retry: OptionalRetry = gapic_v1.method.DEFAULT,
63-
timeout: Optional[float] = None,
63+
timeout: Union[float, object] = gapic_v1.method.DEFAULT,
6464
metadata: Sequence[Tuple[str, str]] = (),
6565
) -> operations_pb2.Operation:
6666
r"""Gets the latest state of a long-running operation.
@@ -113,7 +113,7 @@
113113
request: Optional[operations_pb2.DeleteOperationRequest] = None,
114114
*,
115115
retry: OptionalRetry = gapic_v1.method.DEFAULT,
116-
timeout: Optional[float] = None,
116+
timeout: Union[float, object] = gapic_v1.method.DEFAULT,
117117
metadata: Sequence[Tuple[str, str]] = (),
118118
) -> None:
119119
r"""Deletes a long-running operation.
@@ -166,7 +166,7 @@
166166
request: Optional[operations_pb2.CancelOperationRequest] = None,
167167
*,
168168
retry: OptionalRetry = gapic_v1.method.DEFAULT,
169-
timeout: Optional[float] = None,
169+
timeout: Union[float, object] = gapic_v1.method.DEFAULT,
170170
metadata: Sequence[Tuple[str, str]] = (),
171171
) -> None:
172172
r"""Starts asynchronous cancellation on a long-running operation.
@@ -218,7 +218,7 @@
218218
request: Optional[operations_pb2.WaitOperationRequest] = None,
219219
*,
220220
retry: OptionalRetry = gapic_v1.method.DEFAULT,
221-
timeout: Optional[float] = None,
221+
timeout: Union[float, object] = gapic_v1.method.DEFAULT,
222222
metadata: Sequence[Tuple[str, str]] = (),
223223
) -> operations_pb2.Operation:
224224
r"""Waits until the specified long-running operation is done or reaches at most
@@ -277,7 +277,7 @@
277277
request: Optional[iam_policy_pb2.SetIamPolicyRequest] = None,
278278
*,
279279
retry: OptionalRetry = gapic_v1.method.DEFAULT,
280-
timeout: Optional[float] = None,
280+
timeout: Union[float, object] = gapic_v1.method.DEFAULT,
281281
metadata: Sequence[Tuple[str, str]] = (),
282282
) -> policy_pb2.Policy:
283283
r"""Sets the IAM access control policy on the specified function.
@@ -396,7 +396,7 @@
396396
request: Optional[iam_policy_pb2.GetIamPolicyRequest] = None,
397397
*,
398398
retry: OptionalRetry = gapic_v1.method.DEFAULT,
399-
timeout: Optional[float] = None,
399+
timeout: Union[float, object] = gapic_v1.method.DEFAULT,
400400
metadata: Sequence[Tuple[str, str]] = (),
401401
) -> policy_pb2.Policy:
402402
r"""Gets the IAM access control policy for a function.
@@ -516,7 +516,7 @@
516516
request: Optional[iam_policy_pb2.TestIamPermissionsRequest] = None,
517517
*,
518518
retry: OptionalRetry = gapic_v1.method.DEFAULT,
519-
timeout: Optional[float] = None,
519+
timeout: Union[float, object] = gapic_v1.method.DEFAULT,
520520
metadata: Sequence[Tuple[str, str]] = (),
521521
) -> iam_policy_pb2.TestIamPermissionsResponse:
522522
r"""Tests the specified IAM permissions against the IAM access control
@@ -578,7 +578,7 @@
578578
request: Optional[locations_pb2.GetLocationRequest] = None,
579579
*,
580580
retry: OptionalRetry = gapic_v1.method.DEFAULT,
581-
timeout: Optional[float] = None,
581+
timeout: Union[float, object] = gapic_v1.method.DEFAULT,
582582
metadata: Sequence[Tuple[str, str]] = (),
583583
) -> locations_pb2.Location:
584584
r"""Gets information about a location.
@@ -631,7 +631,7 @@
631631
request: Optional[locations_pb2.ListLocationsRequest] = None,
632632
*,
633633
retry: OptionalRetry = gapic_v1.method.DEFAULT,
634-
timeout: Optional[float] = None,
634+
timeout: Union[float, object] = gapic_v1.method.DEFAULT,
635635
metadata: Sequence[Tuple[str, str]] = (),
636636
) -> locations_pb2.ListLocationsResponse:
637637
r"""Lists information about the supported locations for this service.

packages/gapic-generator/gapic/ads-templates/%namespace/%name/%version/%sub/services/%service/client.py.j2

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ class {{ service.client_name }}(metaclass={{ service.client_name }}Meta):
350350
*,
351351
{% endif %}
352352
retry: OptionalRetry = gapic_v1.method.DEFAULT,
353-
timeout: Optional[float] = None,
353+
timeout: Union[float, object] = gapic_v1.method.DEFAULT,
354354
metadata: Sequence[Tuple[str, str]] = (),
355355
{% if not method.server_streaming %}
356356
) -> {{ method.client_output.ident }}:
@@ -519,7 +519,7 @@ class {{ service.client_name }}(metaclass={{ service.client_name }}Meta):
519519
request: Optional[iam_policy_pb2.SetIamPolicyRequest] = None,
520520
*,
521521
retry: OptionalRetry = gapic_v1.method.DEFAULT,
522-
timeout: Optional[float] = None,
522+
timeout: Union[float, object] = gapic_v1.method.DEFAULT,
523523
metadata: Sequence[Tuple[str, str]] = (),
524524
) -> policy_pb2.Policy:
525525
r"""Sets the IAM access control policy on the specified function.
@@ -636,7 +636,7 @@ class {{ service.client_name }}(metaclass={{ service.client_name }}Meta):
636636
request: Optional[iam_policy_pb2.GetIamPolicyRequest] = None,
637637
*,
638638
retry: OptionalRetry = gapic_v1.method.DEFAULT,
639-
timeout: Optional[float] = None,
639+
timeout: Union[float, object] = gapic_v1.method.DEFAULT,
640640
metadata: Sequence[Tuple[str, str]] = (),
641641
) -> policy_pb2.Policy:
642642
r"""Gets the IAM access control policy for a function.
@@ -753,7 +753,7 @@ class {{ service.client_name }}(metaclass={{ service.client_name }}Meta):
753753
request: Optional[iam_policy_pb2.TestIamPermissionsRequest] = None,
754754
*,
755755
retry: OptionalRetry = gapic_v1.method.DEFAULT,
756-
timeout: Optional[float] = None,
756+
timeout: Union[float, object] = gapic_v1.method.DEFAULT,
757757
metadata: Sequence[Tuple[str, str]] = (),
758758
) -> iam_policy_pb2.TestIamPermissionsResponse:
759759
r"""Tests the specified IAM permissions against the IAM access control

packages/gapic-generator/gapic/ads-templates/%namespace/%name/%version/%sub/services/%service/transports/rest.py.j2

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,8 @@ class {{service.name}}RestTransport({{service.name}}Transport):
251251
# use the credentials which are saved
252252
credentials=self._credentials,
253253
scopes=self._scopes,
254-
http_options=http_options)
254+
http_options=http_options,
255+
path_prefix="{{ service.client_package_version }}")
255256

256257
self._operations_client = operations_v1.AbstractOperationsClient(transport=rest_transport)
257258

@@ -282,9 +283,9 @@ class {{service.name}}RestTransport({{service.name}}Transport):
282283

283284
def __call__(self,
284285
request: {{method.input.ident}}, *,
285-
retry: OptionalRetry = gapic_v1.method.DEFAULT,
286-
timeout: Optional[float] = None,
287-
metadata: Sequence[Tuple[str, str]] = (),
286+
retry: OptionalRetry=gapic_v1.method.DEFAULT,
287+
timeout: Optional[float]=None,
288+
metadata: Sequence[Tuple[str, str]]=(),
288289
){% if not method.void %} -> {% if not method.server_streaming %}{{method.output.ident}}{% else %}rest_streaming.ResponseIterator{% endif %}{% endif %}:
289290
{% if method.http_options and not method.client_streaming %}
290291
r"""Call the {{- ' ' -}}

packages/gapic-generator/gapic/schema/wrappers.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1637,6 +1637,10 @@ def client_name(self) -> str:
16371637
"""Returns the name of the generated client class"""
16381638
return self.name + "Client"
16391639

1640+
@property
1641+
def client_package_version(self) -> str:
1642+
return self.meta.address.package[-1] if self.meta.address.package else ""
1643+
16401644
@property
16411645
def async_client_name(self) -> str:
16421646
"""Returns the name of the generated AsyncIO client class"""

packages/gapic-generator/gapic/templates/%namespace/%name_%version/%sub/services/%service/_async_mixins.py.j2

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
request: Optional[operations_pb2.ListOperationsRequest] = None,
99
*,
1010
retry: OptionalRetry = gapic_v1.method.DEFAULT,
11-
timeout: Optional[float] = None,
11+
timeout: Union[float, object] = gapic_v1.method.DEFAULT,
1212
metadata: Sequence[Tuple[str, str]] = (),
1313
) -> operations_pb2.ListOperationsResponse:
1414
r"""Lists operations that match the specified filter in the request.
@@ -62,7 +62,7 @@
6262
request: Optional[operations_pb2.GetOperationRequest] = None,
6363
*,
6464
retry: OptionalRetry = gapic_v1.method.DEFAULT,
65-
timeout: Optional[float] = None,
65+
timeout: Union[float, object] = gapic_v1.method.DEFAULT,
6666
metadata: Sequence[Tuple[str, str]] = (),
6767
) -> operations_pb2.Operation:
6868
r"""Gets the latest state of a long-running operation.
@@ -115,7 +115,7 @@
115115
request: Optional[operations_pb2.DeleteOperationRequest] = None,
116116
*,
117117
retry: OptionalRetry = gapic_v1.method.DEFAULT,
118-
timeout: Optional[float] = None,
118+
timeout: Union[float, object] = gapic_v1.method.DEFAULT,
119119
metadata: Sequence[Tuple[str, str]] = (),
120120
) -> None:
121121
r"""Deletes a long-running operation.
@@ -168,7 +168,7 @@
168168
request: Optional[operations_pb2.CancelOperationRequest] = None,
169169
*,
170170
retry: OptionalRetry = gapic_v1.method.DEFAULT,
171-
timeout: Optional[float] = None,
171+
timeout: Union[float, object] = gapic_v1.method.DEFAULT,
172172
metadata: Sequence[Tuple[str, str]] = (),
173173
) -> None:
174174
r"""Starts asynchronous cancellation on a long-running operation.
@@ -220,7 +220,7 @@
220220
request: Optional[operations_pb2.WaitOperationRequest] = None,
221221
*,
222222
retry: OptionalRetry = gapic_v1.method.DEFAULT,
223-
timeout: Optional[float] = None,
223+
timeout: Union[float, object] = gapic_v1.method.DEFAULT,
224224
metadata: Sequence[Tuple[str, str]] = (),
225225
) -> operations_pb2.Operation:
226226
r"""Waits until the specified long-running operation is done or reaches at most
@@ -284,7 +284,7 @@
284284
request: Optional[iam_policy_pb2.SetIamPolicyRequest] = None,
285285
*,
286286
retry: OptionalRetry = gapic_v1.method.DEFAULT,
287-
timeout: Optional[float] = None,
287+
timeout: Union[float, object] = gapic_v1.method.DEFAULT,
288288
metadata: Sequence[Tuple[str, str]] = (),
289289
) -> policy_pb2.Policy:
290290
r"""Sets the IAM access control policy on the specified function.
@@ -403,7 +403,7 @@
403403
request: Optional[iam_policy_pb2.GetIamPolicyRequest] = None,
404404
*,
405405
retry: OptionalRetry = gapic_v1.method.DEFAULT,
406-
timeout: Optional[float] = None,
406+
timeout: Union[float, object] = gapic_v1.method.DEFAULT,
407407
metadata: Sequence[Tuple[str, str]] = (),
408408
) -> policy_pb2.Policy:
409409
r"""Gets the IAM access control policy for a function.
@@ -523,7 +523,7 @@
523523
request: Optional[iam_policy_pb2.TestIamPermissionsRequest] = None,
524524
*,
525525
retry: OptionalRetry = gapic_v1.method.DEFAULT,
526-
timeout: Optional[float] = None,
526+
timeout: Union[float, object] = gapic_v1.method.DEFAULT,
527527
metadata: Sequence[Tuple[str, str]] = (),
528528
) -> iam_policy_pb2.TestIamPermissionsResponse:
529529
r"""Tests the specified IAM permissions against the IAM access control
@@ -585,7 +585,7 @@
585585
request: Optional[locations_pb2.GetLocationRequest] = None,
586586
*,
587587
retry: OptionalRetry = gapic_v1.method.DEFAULT,
588-
timeout: Optional[float] = None,
588+
timeout: Union[float, object] = gapic_v1.method.DEFAULT,
589589
metadata: Sequence[Tuple[str, str]] = (),
590590
) -> locations_pb2.Location:
591591
r"""Gets information about a location.
@@ -638,7 +638,7 @@
638638
request: Optional[locations_pb2.ListLocationsRequest] = None,
639639
*,
640640
retry: OptionalRetry = gapic_v1.method.DEFAULT,
641-
timeout: Optional[float] = None,
641+
timeout: Union[float, object] = gapic_v1.method.DEFAULT,
642642
metadata: Sequence[Tuple[str, str]] = (),
643643
) -> locations_pb2.ListLocationsResponse:
644644
r"""Lists information about the supported locations for this service.

packages/gapic-generator/gapic/templates/%namespace/%name_%version/%sub/services/%service/_client_macros.j2

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
*,
2828
{% endif %}
2929
retry: OptionalRetry = gapic_v1.method.DEFAULT,
30-
timeout: Optional[float] = None,
30+
timeout: Union[float, object] = gapic_v1.method.DEFAULT,
3131
metadata: Sequence[Tuple[str, str]] = (),
3232
{% if method.extended_lro and not full_extended_lro %}{# This is a hack to preserve backwards compatibility with the "unary" surfaces #}
3333
) -> {{ method.extended_lro.operation_type.ident }}:

packages/gapic-generator/gapic/templates/%namespace/%name_%version/%sub/services/%service/_mixins.py.j2

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
request: Optional[operations_pb2.ListOperationsRequest] = None,
77
*,
88
retry: OptionalRetry = gapic_v1.method.DEFAULT,
9-
timeout: Optional[float] = None,
9+
timeout: Union[float, object] = gapic_v1.method.DEFAULT,
1010
metadata: Sequence[Tuple[str, str]] = (),
1111
) -> operations_pb2.ListOperationsResponse:
1212
r"""Lists operations that match the specified filter in the request.
@@ -60,7 +60,7 @@
6060
request: Optional[operations_pb2.GetOperationRequest] = None,
6161
*,
6262
retry: OptionalRetry = gapic_v1.method.DEFAULT,
63-
timeout: Optional[float] = None,
63+
timeout: Union[float, object] = gapic_v1.method.DEFAULT,
6464
metadata: Sequence[Tuple[str, str]] = (),
6565
) -> operations_pb2.Operation:
6666
r"""Gets the latest state of a long-running operation.
@@ -113,7 +113,7 @@
113113
request: Optional[operations_pb2.DeleteOperationRequest] = None,
114114
*,
115115
retry: OptionalRetry = gapic_v1.method.DEFAULT,
116-
timeout: Optional[float] = None,
116+
timeout: Union[float, object] = gapic_v1.method.DEFAULT,
117117
metadata: Sequence[Tuple[str, str]] = (),
118118
) -> None:
119119
r"""Deletes a long-running operation.
@@ -166,7 +166,7 @@
166166
request: Optional[operations_pb2.CancelOperationRequest] = None,
167167
*,
168168
retry: OptionalRetry = gapic_v1.method.DEFAULT,
169-
timeout: Optional[float] = None,
169+
timeout: Union[float, object] = gapic_v1.method.DEFAULT,
170170
metadata: Sequence[Tuple[str, str]] = (),
171171
) -> None:
172172
r"""Starts asynchronous cancellation on a long-running operation.
@@ -218,7 +218,7 @@
218218
request: Optional[operations_pb2.WaitOperationRequest] = None,
219219
*,
220220
retry: OptionalRetry = gapic_v1.method.DEFAULT,
221-
timeout: Optional[float] = None,
221+
timeout: Union[float, object] = gapic_v1.method.DEFAULT,
222222
metadata: Sequence[Tuple[str, str]] = (),
223223
) -> operations_pb2.Operation:
224224
r"""Waits until the specified long-running operation is done or reaches at most
@@ -282,7 +282,7 @@
282282
request: Optional[iam_policy_pb2.SetIamPolicyRequest] = None,
283283
*,
284284
retry: OptionalRetry = gapic_v1.method.DEFAULT,
285-
timeout: Optional[float] = None,
285+
timeout: Union[float, object] = gapic_v1.method.DEFAULT,
286286
metadata: Sequence[Tuple[str, str]] = (),
287287
) -> policy_pb2.Policy:
288288
r"""Sets the IAM access control policy on the specified function.
@@ -401,7 +401,7 @@
401401
request: Optional[iam_policy_pb2.GetIamPolicyRequest] = None,
402402
*,
403403
retry: OptionalRetry = gapic_v1.method.DEFAULT,
404-
timeout: Optional[float] = None,
404+
timeout: Union[float, object] = gapic_v1.method.DEFAULT,
405405
metadata: Sequence[Tuple[str, str]] = (),
406406
) -> policy_pb2.Policy:
407407
r"""Gets the IAM access control policy for a function.
@@ -521,7 +521,7 @@
521521
request: Optional[iam_policy_pb2.TestIamPermissionsRequest] = None,
522522
*,
523523
retry: OptionalRetry = gapic_v1.method.DEFAULT,
524-
timeout: Optional[float] = None,
524+
timeout: Union[float, object] = gapic_v1.method.DEFAULT,
525525
metadata: Sequence[Tuple[str, str]] = (),
526526
) -> iam_policy_pb2.TestIamPermissionsResponse:
527527
r"""Tests the specified IAM permissions against the IAM access control
@@ -583,7 +583,7 @@
583583
request: Optional[locations_pb2.GetLocationRequest] = None,
584584
*,
585585
retry: OptionalRetry = gapic_v1.method.DEFAULT,
586-
timeout: Optional[float] = None,
586+
timeout: Union[float, object] = gapic_v1.method.DEFAULT,
587587
metadata: Sequence[Tuple[str, str]] = (),
588588
) -> locations_pb2.Location:
589589
r"""Gets information about a location.
@@ -636,7 +636,7 @@
636636
request: Optional[locations_pb2.ListLocationsRequest] = None,
637637
*,
638638
retry: OptionalRetry = gapic_v1.method.DEFAULT,
639-
timeout: Optional[float] = None,
639+
timeout: Union[float, object] = gapic_v1.method.DEFAULT,
640640
metadata: Sequence[Tuple[str, str]] = (),
641641
) -> locations_pb2.ListLocationsResponse:
642642
r"""Lists information about the supported locations for this service.

packages/gapic-generator/gapic/templates/%namespace/%name_%version/%sub/services/%service/async_client.py.j2

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ class {{ service.async_client_name }}:
205205
*,
206206
{% endif %}
207207
retry: OptionalRetry = gapic_v1.method.DEFAULT,
208-
timeout: Optional[float] = None,
208+
timeout: Union[float, object] = gapic_v1.method.DEFAULT,
209209
metadata: Sequence[Tuple[str, str]] = (),
210210
{% if not method.server_streaming %}
211211
) -> {{ method.client_output_async.ident }}:
@@ -390,7 +390,7 @@ class {{ service.async_client_name }}:
390390
request: Optional[iam_policy_pb2.SetIamPolicyRequest] = None,
391391
*,
392392
retry: OptionalRetry = gapic_v1.method.DEFAULT,
393-
timeout: Optional[float] = None,
393+
timeout: Union[float, object] = gapic_v1.method.DEFAULT,
394394
metadata: Sequence[Tuple[str, str]] = (),
395395
) -> policy_pb2.Policy:
396396
r"""Sets the IAM access control policy on the specified function.
@@ -504,7 +504,7 @@ class {{ service.async_client_name }}:
504504
request: Optional[iam_policy_pb2.GetIamPolicyRequest] = None,
505505
*,
506506
retry: OptionalRetry = gapic_v1.method.DEFAULT,
507-
timeout: Optional[float] = None,
507+
timeout: Union[float, object] = gapic_v1.method.DEFAULT,
508508
metadata: Sequence[Tuple[str, str]] = (),
509509
) -> policy_pb2.Policy:
510510
r"""Gets the IAM access control policy for a function.
@@ -620,7 +620,7 @@ class {{ service.async_client_name }}:
620620
request: Optional[iam_policy_pb2.TestIamPermissionsRequest] = None,
621621
*,
622622
retry: OptionalRetry = gapic_v1.method.DEFAULT,
623-
timeout: Optional[float] = None,
623+
timeout: Union[float, object] = gapic_v1.method.DEFAULT,
624624
metadata: Sequence[Tuple[str, str]] = (),
625625
) -> iam_policy_pb2.TestIamPermissionsResponse:
626626
r"""Tests the specified permissions against the IAM access control

0 commit comments

Comments
 (0)