@@ -254,13 +254,13 @@ def _aggregator(_: GetTaskResponse) -> None:
254
254
255
255
async def wait_for_api_key (
256
256
self ,
257
- operation : str ,
258
257
key : str ,
258
+ operation : str ,
259
259
api_key : Optional [ApiKey ] = None ,
260
260
max_retries : int = 50 ,
261
261
timeout : RetryTimeout = RetryTimeout (),
262
262
request_options : Optional [Union [dict , RequestOptions ]] = None ,
263
- ) -> GetApiKeyResponse :
263
+ ) -> GetApiKeyResponse | None :
264
264
"""
265
265
Helper: Wait for an API key to be added, updated or deleted based on a given `operation`.
266
266
"""
@@ -271,7 +271,7 @@ async def wait_for_api_key(
271
271
"`apiKey` is required when waiting for an `update` operation."
272
272
)
273
273
274
- async def _func (_prev : GetApiKeyResponse ) -> GetApiKeyResponse :
274
+ async def _func (_prev : GetApiKeyResponse | None ) -> GetApiKeyResponse | None :
275
275
try :
276
276
return await self .get_api_key (key = key , request_options = request_options )
277
277
except RequestException as e :
@@ -281,20 +281,25 @@ async def _func(_prev: GetApiKeyResponse) -> GetApiKeyResponse:
281
281
return None
282
282
raise e
283
283
284
- def _aggregator (_ : GetApiKeyResponse ) -> None :
284
+ def _aggregator (_ : GetApiKeyResponse | None ) -> None :
285
285
self ._retry_count += 1
286
286
287
- def _validate (_resp : GetApiKeyResponse ) -> bool :
287
+ def _validate (_resp : GetApiKeyResponse | None ) -> bool :
288
288
if operation == "update" :
289
- for field in api_key :
290
- if isinstance (api_key [field ], list ) and isinstance (
291
- _resp [field ], list
289
+ resp_dict = _resp .to_dict ()
290
+ api_key_dict = (
291
+ api_key .to_dict () if isinstance (api_key , ApiKey ) else api_key
292
+ )
293
+ for field in api_key_dict :
294
+ if isinstance (api_key_dict [field ], list ) and isinstance (
295
+ resp_dict [field ], list
292
296
):
293
- if len (api_key [field ]) != len (_resp [field ]) or any (
294
- v != _resp [field ][i ] for i , v in enumerate (api_key [field ])
297
+ if len (api_key_dict [field ]) != len (resp_dict [field ]) or any (
298
+ v != resp_dict [field ][i ]
299
+ for i , v in enumerate (api_key_dict [field ])
295
300
):
296
301
return False
297
- elif api_key [field ] != _resp [field ]:
302
+ elif api_key_dict [field ] != resp_dict [field ]:
298
303
return False
299
304
return True
300
305
elif operation == "add" :
0 commit comments