Skip to content
This repository was archived by the owner on Sep 5, 2023. It is now read-only.

Commit 0c69bc2

Browse files
fix: use correct retry deadline (#124)
* chore: upgrade gapic-generator-python to 0.43.1 PiperOrigin-RevId: 364411656 Source-Author: Google APIs <noreply@google.com> Source-Date: Mon Mar 22 14:40:22 2021 -0700 Source-Repo: googleapis/googleapis Source-Sha: 149a3a84c29c9b8189576c7442ccb6dcf6a8f95b Source-Link: googleapis/googleapis@149a3a8
1 parent ea43c05 commit 0c69bc2

File tree

16 files changed

+389
-569
lines changed

16 files changed

+389
-569
lines changed

google/cloud/datacatalog_v1/services/data_catalog/async_client.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,7 @@ async def search_catalog(
293293
maximum=60.0,
294294
multiplier=1.3,
295295
predicate=retries.if_exception_type(exceptions.ServiceUnavailable,),
296+
deadline=60.0,
296297
),
297298
default_timeout=60.0,
298299
client_info=DEFAULT_CLIENT_INFO,
@@ -508,6 +509,7 @@ async def get_entry_group(
508509
maximum=60.0,
509510
multiplier=1.3,
510511
predicate=retries.if_exception_type(exceptions.ServiceUnavailable,),
512+
deadline=60.0,
511513
),
512514
default_timeout=60.0,
513515
client_info=DEFAULT_CLIENT_INFO,
@@ -756,6 +758,7 @@ async def list_entry_groups(
756758
maximum=60.0,
757759
multiplier=1.3,
758760
predicate=retries.if_exception_type(exceptions.ServiceUnavailable,),
761+
deadline=60.0,
759762
),
760763
default_timeout=60.0,
761764
client_info=DEFAULT_CLIENT_INFO,
@@ -1163,6 +1166,7 @@ async def get_entry(
11631166
maximum=60.0,
11641167
multiplier=1.3,
11651168
predicate=retries.if_exception_type(exceptions.ServiceUnavailable,),
1169+
deadline=60.0,
11661170
),
11671171
default_timeout=60.0,
11681172
client_info=DEFAULT_CLIENT_INFO,
@@ -1233,6 +1237,7 @@ async def lookup_entry(
12331237
maximum=60.0,
12341238
multiplier=1.3,
12351239
predicate=retries.if_exception_type(exceptions.ServiceUnavailable,),
1240+
deadline=60.0,
12361241
),
12371242
default_timeout=60.0,
12381243
client_info=DEFAULT_CLIENT_INFO,
@@ -1311,6 +1316,7 @@ async def list_entries(
13111316
maximum=60.0,
13121317
multiplier=1.3,
13131318
predicate=retries.if_exception_type(exceptions.ServiceUnavailable,),
1319+
deadline=60.0,
13141320
),
13151321
default_timeout=60.0,
13161322
client_info=DEFAULT_CLIENT_INFO,
@@ -2428,6 +2434,7 @@ async def list_tags(
24282434
maximum=60.0,
24292435
multiplier=1.3,
24302436
predicate=retries.if_exception_type(exceptions.ServiceUnavailable,),
2437+
deadline=60.0,
24312438
),
24322439
default_timeout=60.0,
24332440
client_info=DEFAULT_CLIENT_INFO,
@@ -2732,6 +2739,7 @@ async def get_iam_policy(
27322739
maximum=60.0,
27332740
multiplier=1.3,
27342741
predicate=retries.if_exception_type(exceptions.ServiceUnavailable,),
2742+
deadline=60.0,
27352743
),
27362744
default_timeout=60.0,
27372745
client_info=DEFAULT_CLIENT_INFO,

google/cloud/datacatalog_v1/services/data_catalog/transports/base.py

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -73,17 +73,20 @@ def __init__(
7373
scope (Optional[Sequence[str]]): A list of scopes.
7474
quota_project_id (Optional[str]): An optional project to use for billing
7575
and quota.
76-
client_info (google.api_core.gapic_v1.client_info.ClientInfo):
77-
The client info used to send a user-agent string along with
78-
API requests. If ``None``, then default info will be used.
79-
Generally, you only need to set this if you're developing
76+
client_info (google.api_core.gapic_v1.client_info.ClientInfo):
77+
The client info used to send a user-agent string along with
78+
API requests. If ``None``, then default info will be used.
79+
Generally, you only need to set this if you're developing
8080
your own client library.
8181
"""
8282
# Save the hostname. Default to port 443 (HTTPS) if none is specified.
8383
if ":" not in host:
8484
host += ":443"
8585
self._host = host
8686

87+
# Save the scopes.
88+
self._scopes = scopes or self.AUTH_SCOPES
89+
8790
# If no credentials are provided, then determine the appropriate
8891
# defaults.
8992
if credentials and credentials_file:
@@ -93,20 +96,17 @@ def __init__(
9396

9497
if credentials_file is not None:
9598
credentials, _ = auth.load_credentials_from_file(
96-
credentials_file, scopes=scopes, quota_project_id=quota_project_id
99+
credentials_file, scopes=self._scopes, quota_project_id=quota_project_id
97100
)
98101

99102
elif credentials is None:
100103
credentials, _ = auth.default(
101-
scopes=scopes, quota_project_id=quota_project_id
104+
scopes=self._scopes, quota_project_id=quota_project_id
102105
)
103106

104107
# Save the credentials.
105108
self._credentials = credentials
106109

107-
# Lifted into its own function so it can be stubbed out during tests.
108-
self._prep_wrapped_messages(client_info)
109-
110110
def _prep_wrapped_messages(self, client_info):
111111
# Precompute the wrapped methods.
112112
self._wrapped_methods = {
@@ -117,6 +117,7 @@ def _prep_wrapped_messages(self, client_info):
117117
maximum=60.0,
118118
multiplier=1.3,
119119
predicate=retries.if_exception_type(exceptions.ServiceUnavailable,),
120+
deadline=60.0,
120121
),
121122
default_timeout=60.0,
122123
client_info=client_info,
@@ -131,6 +132,7 @@ def _prep_wrapped_messages(self, client_info):
131132
maximum=60.0,
132133
multiplier=1.3,
133134
predicate=retries.if_exception_type(exceptions.ServiceUnavailable,),
135+
deadline=60.0,
134136
),
135137
default_timeout=60.0,
136138
client_info=client_info,
@@ -148,6 +150,7 @@ def _prep_wrapped_messages(self, client_info):
148150
maximum=60.0,
149151
multiplier=1.3,
150152
predicate=retries.if_exception_type(exceptions.ServiceUnavailable,),
153+
deadline=60.0,
151154
),
152155
default_timeout=60.0,
153156
client_info=client_info,
@@ -168,6 +171,7 @@ def _prep_wrapped_messages(self, client_info):
168171
maximum=60.0,
169172
multiplier=1.3,
170173
predicate=retries.if_exception_type(exceptions.ServiceUnavailable,),
174+
deadline=60.0,
171175
),
172176
default_timeout=60.0,
173177
client_info=client_info,
@@ -179,6 +183,7 @@ def _prep_wrapped_messages(self, client_info):
179183
maximum=60.0,
180184
multiplier=1.3,
181185
predicate=retries.if_exception_type(exceptions.ServiceUnavailable,),
186+
deadline=60.0,
182187
),
183188
default_timeout=60.0,
184189
client_info=client_info,
@@ -190,6 +195,7 @@ def _prep_wrapped_messages(self, client_info):
190195
maximum=60.0,
191196
multiplier=1.3,
192197
predicate=retries.if_exception_type(exceptions.ServiceUnavailable,),
198+
deadline=60.0,
193199
),
194200
default_timeout=60.0,
195201
client_info=client_info,
@@ -242,6 +248,7 @@ def _prep_wrapped_messages(self, client_info):
242248
maximum=60.0,
243249
multiplier=1.3,
244250
predicate=retries.if_exception_type(exceptions.ServiceUnavailable,),
251+
deadline=60.0,
245252
),
246253
default_timeout=60.0,
247254
client_info=client_info,
@@ -256,6 +263,7 @@ def _prep_wrapped_messages(self, client_info):
256263
maximum=60.0,
257264
multiplier=1.3,
258265
predicate=retries.if_exception_type(exceptions.ServiceUnavailable,),
266+
deadline=60.0,
259267
),
260268
default_timeout=60.0,
261269
client_info=client_info,

google/cloud/datacatalog_v1/services/data_catalog/transports/grpc.py

Lines changed: 37 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -111,96 +111,69 @@ def __init__(
111111
google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials``
112112
and ``credentials_file`` are passed.
113113
"""
114+
self._grpc_channel = None
114115
self._ssl_channel_credentials = ssl_channel_credentials
116+
self._stubs: Dict[str, Callable] = {}
115117

116118
if api_mtls_endpoint:
117119
warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning)
118120
if client_cert_source:
119121
warnings.warn("client_cert_source is deprecated", DeprecationWarning)
120122

121123
if channel:
122-
# Sanity check: Ensure that channel and credentials are not both
123-
# provided.
124+
# Ignore credentials if a channel was passed.
124125
credentials = False
125-
126126
# If a channel was explicitly provided, set it.
127127
self._grpc_channel = channel
128128
self._ssl_channel_credentials = None
129-
elif api_mtls_endpoint:
130-
host = (
131-
api_mtls_endpoint
132-
if ":" in api_mtls_endpoint
133-
else api_mtls_endpoint + ":443"
134-
)
135-
136-
if credentials is None:
137-
credentials, _ = auth.default(
138-
scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id
139-
)
140-
141-
# Create SSL credentials with client_cert_source or application
142-
# default SSL credentials.
143-
if client_cert_source:
144-
cert, key = client_cert_source()
145-
ssl_credentials = grpc.ssl_channel_credentials(
146-
certificate_chain=cert, private_key=key
147-
)
148-
else:
149-
ssl_credentials = SslCredentials().ssl_credentials
150129

151-
# create a new channel. The provided one is ignored.
152-
self._grpc_channel = type(self).create_channel(
153-
host,
154-
credentials=credentials,
155-
credentials_file=credentials_file,
156-
ssl_credentials=ssl_credentials,
157-
scopes=scopes or self.AUTH_SCOPES,
158-
quota_project_id=quota_project_id,
159-
options=[
160-
("grpc.max_send_message_length", -1),
161-
("grpc.max_receive_message_length", -1),
162-
],
163-
)
164-
self._ssl_channel_credentials = ssl_credentials
165130
else:
166-
host = host if ":" in host else host + ":443"
131+
if api_mtls_endpoint:
132+
host = api_mtls_endpoint
133+
134+
# Create SSL credentials with client_cert_source or application
135+
# default SSL credentials.
136+
if client_cert_source:
137+
cert, key = client_cert_source()
138+
self._ssl_channel_credentials = grpc.ssl_channel_credentials(
139+
certificate_chain=cert, private_key=key
140+
)
141+
else:
142+
self._ssl_channel_credentials = SslCredentials().ssl_credentials
167143

168-
if credentials is None:
169-
credentials, _ = auth.default(
170-
scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id
171-
)
144+
else:
145+
if client_cert_source_for_mtls and not ssl_channel_credentials:
146+
cert, key = client_cert_source_for_mtls()
147+
self._ssl_channel_credentials = grpc.ssl_channel_credentials(
148+
certificate_chain=cert, private_key=key
149+
)
172150

173-
if client_cert_source_for_mtls and not ssl_channel_credentials:
174-
cert, key = client_cert_source_for_mtls()
175-
self._ssl_channel_credentials = grpc.ssl_channel_credentials(
176-
certificate_chain=cert, private_key=key
177-
)
151+
# The base transport sets the host, credentials and scopes
152+
super().__init__(
153+
host=host,
154+
credentials=credentials,
155+
credentials_file=credentials_file,
156+
scopes=scopes,
157+
quota_project_id=quota_project_id,
158+
client_info=client_info,
159+
)
178160

179-
# create a new channel. The provided one is ignored.
161+
if not self._grpc_channel:
180162
self._grpc_channel = type(self).create_channel(
181-
host,
182-
credentials=credentials,
163+
self._host,
164+
credentials=self._credentials,
183165
credentials_file=credentials_file,
166+
scopes=self._scopes,
184167
ssl_credentials=self._ssl_channel_credentials,
185-
scopes=scopes or self.AUTH_SCOPES,
186168
quota_project_id=quota_project_id,
187169
options=[
188170
("grpc.max_send_message_length", -1),
189171
("grpc.max_receive_message_length", -1),
190172
],
191173
)
192174

193-
self._stubs = {} # type: Dict[str, Callable]
194-
195-
# Run the base constructor.
196-
super().__init__(
197-
host=host,
198-
credentials=credentials,
199-
credentials_file=credentials_file,
200-
scopes=scopes or self.AUTH_SCOPES,
201-
quota_project_id=quota_project_id,
202-
client_info=client_info,
203-
)
175+
# Wrap messages. This must be done after self._grpc_channel exists
176+
self._prep_wrapped_messages(client_info)
204177

205178
@classmethod
206179
def create_channel(
@@ -214,7 +187,7 @@ def create_channel(
214187
) -> grpc.Channel:
215188
"""Create and return a gRPC channel object.
216189
Args:
217-
address (Optional[str]): The host for the channel to use.
190+
host (Optional[str]): The host for the channel to use.
218191
credentials (Optional[~.Credentials]): The
219192
authorization credentials to attach to requests. These
220193
credentials identify this application to the service. If

0 commit comments

Comments
 (0)