fix: avoid forcing lazy client construction in lightweight accessors

Two sites that were mechanically rewritten by the lazy-getter
regex shouldn't actually go through the lazy getter:

- `BedrockCompletion._ensure_async_client` manages its own client
  lifecycle through `aiobotocore` inside an exit stack. Its trailing
  `return self._get_async_client()` was a redundant indirection
  through a stub method that doesn't even attempt to build a client.
  Return the cached attribute directly.

- `GeminiCompletion._get_client_params` is a lightweight config
  accessor used at `to_config_dict()` time. Calling `_get_sync_client()`
  here forced client construction (and would raise `ValueError` when
  credentials aren't set) just to check the `vertexai` attribute. Read
  `self._client` directly and null-guard before the `hasattr` check.
This commit is contained in:
Greyson LaLonde
2026-04-12 04:34:23 +08:00
parent 8312e1caad
commit 9eb45950e4
2 changed files with 4 additions and 3 deletions

View File

@@ -1198,7 +1198,7 @@ class BedrockCompletion(BaseLLM):
)
self._async_client = client
self._async_client_initialized = True
return self._get_async_client()
return self._async_client
async def _ahandle_converse(
self,

View File

@@ -244,8 +244,9 @@ class GeminiCompletion(BaseLLM):
if (
hasattr(self, "client")
and hasattr(self._get_sync_client(), "vertexai")
and self._get_sync_client().vertexai
and self._client is not None
and hasattr(self._client, "vertexai")
and self._client.vertexai
):
# Vertex AI configuration
params.update(