fix(gen): restore async client with langchain-google-genai >= 4.3.7 - #165
Merged
Merged
Conversation
The SDK's ChatGoogleGenerativeAI shadows the upstream `validate_environment` validator to inject the AI Core client. Since langchain-google-genai 4.3.7 that upstream validator also registers the client with a `_ClientCleanup` object which the `async_client` property and `aclose()` dereference, so every async call failed with AttributeError. Register the injected client in a validator of our own on the chat class, add a unit test covering `async_client` and `aclose()`, lift the `<4.3.7` pin introduced as a stopgap in SAP#122/SAP#129, and update the stale pin in README_sphynx.md. Refs SAP#152
friedrichwilken
requested review from
OscarDDD,
alpkom,
mwien and
yamaceay
as code owners
September 24, 2026 17:25
3 tasks
alpkom
approved these changes
Sep 25, 2026
Contributor
|
I've tested this end-to-end explicitly, and it works just fine. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Context
Closes #152.
langchain-google-genaiwas pinned to<4.3.7in #122 / #129 as a stopgap for an unspecified bug. Issue 152 asks to lift the pin so consumers can take patch-level upgrades.What this PR does and why it is needed
Problem: the SDK's
ChatGoogleGenerativeAIoverrides an upstream pydantic validator (validate_environment) to inject the AI Core client, and since 4.3.7 upstream also does its async setup in that validator, so the override drops it and every async call fails:Solution: do that async setup in a validator of our own. A new after-validator
_register_client_cleanuponChatGoogleGenerativeAIwraps the injected client in upstream's_ClientCleanup, which is whatasync_clientandaclose()read. The override itself has to stay because upstream overwritesself.clientunconditionally. Embeddings are untouched; upstream's embeddings have no such setup._ClientCleanupis a private upstream name. It is imported unconditionally: the pin guarantees it exists, and if upstream ever moves it the SDK fails at import time instead of on the first async call.Also: pin lifted to
langchain-google-genai~=4.4.0,uv.lockregenerated (only that package changes), stale pin inREADME_sphynx.mdupdated.Testing
test_async_client_available: assertsasync_clientresolves andaclose()completes, with a mocked proxy client. Fails on 4.4.0 without the fix, passes with it.TestAsyncGoogleGenerativeAI) not run locally (no working AI Core credentials at hand). They exercise exactly this path and run in the CI integration job.