Skip to content

Commit f9586d4

Browse files
fix: use correct retry deadline (#331)
* changes without context autosynth cannot find the source of changes triggered by earlier changes in this repository, or by version upgrades to tools such as linters. * chore: upgrade gapic-generator-python to 0.43.1 PiperOrigin-RevId: 364411656 Source-Author: Google APIs <[email protected]> Source-Date: Mon Mar 22 14:40:22 2021 -0700 Source-Repo: googleapis/googleapis Source-Sha: 149a3a84c29c9b8189576c7442ccb6dcf6a8f95b Source-Link: googleapis/googleapis@149a3a8 Co-authored-by: Christopher Wilcox <[email protected]>
1 parent 96446e4 commit f9586d4

File tree

9 files changed

+216
-286
lines changed

9 files changed

+216
-286
lines changed

google/cloud/firestore_admin_v1/services/firestore_admin/async_client.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,7 @@ async def list_indexes(
353353
exceptions.InternalServerError,
354354
exceptions.ServiceUnavailable,
355355
),
356+
deadline=60.0,
356357
),
357358
default_timeout=60.0,
358359
client_info=DEFAULT_CLIENT_INFO,
@@ -443,6 +444,7 @@ async def get_index(
443444
exceptions.InternalServerError,
444445
exceptions.ServiceUnavailable,
445446
),
447+
deadline=60.0,
446448
),
447449
default_timeout=60.0,
448450
client_info=DEFAULT_CLIENT_INFO,
@@ -520,6 +522,7 @@ async def delete_index(
520522
exceptions.InternalServerError,
521523
exceptions.ServiceUnavailable,
522524
),
525+
deadline=60.0,
523526
),
524527
default_timeout=60.0,
525528
client_info=DEFAULT_CLIENT_INFO,
@@ -605,6 +608,7 @@ async def get_field(
605608
exceptions.InternalServerError,
606609
exceptions.ServiceUnavailable,
607610
),
611+
deadline=60.0,
608612
),
609613
default_timeout=60.0,
610614
client_info=DEFAULT_CLIENT_INFO,
@@ -801,6 +805,7 @@ async def list_fields(
801805
exceptions.InternalServerError,
802806
exceptions.ServiceUnavailable,
803807
),
808+
deadline=60.0,
804809
),
805810
default_timeout=60.0,
806811
client_info=DEFAULT_CLIENT_INFO,

google/cloud/firestore_admin_v1/services/firestore_admin/transports/base.py

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

91+
# Save the scopes.
92+
self._scopes = scopes or self.AUTH_SCOPES
93+
9194
# If no credentials are provided, then determine the appropriate
9295
# defaults.
9396
if credentials and credentials_file:
@@ -97,20 +100,17 @@ def __init__(
97100

98101
if credentials_file is not None:
99102
credentials, _ = auth.load_credentials_from_file(
100-
credentials_file, scopes=scopes, quota_project_id=quota_project_id
103+
credentials_file, scopes=self._scopes, quota_project_id=quota_project_id
101104
)
102105

103106
elif credentials is None:
104107
credentials, _ = auth.default(
105-
scopes=scopes, quota_project_id=quota_project_id
108+
scopes=self._scopes, quota_project_id=quota_project_id
106109
)
107110

108111
# Save the credentials.
109112
self._credentials = credentials
110113

111-
# Lifted into its own function so it can be stubbed out during tests.
112-
self._prep_wrapped_messages(client_info)
113-
114114
def _prep_wrapped_messages(self, client_info):
115115
# Precompute the wrapped methods.
116116
self._wrapped_methods = {
@@ -128,6 +128,7 @@ def _prep_wrapped_messages(self, client_info):
128128
exceptions.InternalServerError,
129129
exceptions.ServiceUnavailable,
130130
),
131+
deadline=60.0,
131132
),
132133
default_timeout=60.0,
133134
client_info=client_info,
@@ -143,6 +144,7 @@ def _prep_wrapped_messages(self, client_info):
143144
exceptions.InternalServerError,
144145
exceptions.ServiceUnavailable,
145146
),
147+
deadline=60.0,
146148
),
147149
default_timeout=60.0,
148150
client_info=client_info,
@@ -158,6 +160,7 @@ def _prep_wrapped_messages(self, client_info):
158160
exceptions.InternalServerError,
159161
exceptions.ServiceUnavailable,
160162
),
163+
deadline=60.0,
161164
),
162165
default_timeout=60.0,
163166
client_info=client_info,
@@ -173,6 +176,7 @@ def _prep_wrapped_messages(self, client_info):
173176
exceptions.InternalServerError,
174177
exceptions.ServiceUnavailable,
175178
),
179+
deadline=60.0,
176180
),
177181
default_timeout=60.0,
178182
client_info=client_info,
@@ -191,6 +195,7 @@ def _prep_wrapped_messages(self, client_info):
191195
exceptions.InternalServerError,
192196
exceptions.ServiceUnavailable,
193197
),
198+
deadline=60.0,
194199
),
195200
default_timeout=60.0,
196201
client_info=client_info,

google/cloud/firestore_admin_v1/services/firestore_admin/transports/grpc.py

Lines changed: 38 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -112,97 +112,70 @@ def __init__(
112112
google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials``
113113
and ``credentials_file`` are passed.
114114
"""
115+
self._grpc_channel = None
115116
self._ssl_channel_credentials = ssl_channel_credentials
117+
self._stubs: Dict[str, Callable] = {}
118+
self._operations_client = None
116119

117120
if api_mtls_endpoint:
118121
warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning)
119122
if client_cert_source:
120123
warnings.warn("client_cert_source is deprecated", DeprecationWarning)
121124

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

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

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

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

180-
# create a new channel. The provided one is ignored.
163+
if not self._grpc_channel:
181164
self._grpc_channel = type(self).create_channel(
182-
host,
183-
credentials=credentials,
165+
self._host,
166+
credentials=self._credentials,
184167
credentials_file=credentials_file,
168+
scopes=self._scopes,
185169
ssl_credentials=self._ssl_channel_credentials,
186-
scopes=scopes or self.AUTH_SCOPES,
187170
quota_project_id=quota_project_id,
188171
options=[
189172
("grpc.max_send_message_length", -1),
190173
("grpc.max_receive_message_length", -1),
191174
],
192175
)
193176

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

207180
@classmethod
208181
def create_channel(
@@ -216,7 +189,7 @@ def create_channel(
216189
) -> grpc.Channel:
217190
"""Create and return a gRPC channel object.
218191
Args:
219-
address (Optional[str]): The host for the channel to use.
192+
host (Optional[str]): The host for the channel to use.
220193
credentials (Optional[~.Credentials]): The
221194
authorization credentials to attach to requests. These
222195
credentials identify this application to the service. If

0 commit comments

Comments
 (0)