Skip to content

fix(gen): restore async client with langchain-google-genai >= 4.3.7 - #165

Merged
alpkom merged 1 commit into
SAP:mainfrom
friedrichwilken:fix-google-genai-async
Sep 25, 2026
Merged

alpkom merged 1 commit into
SAP:mainfrom
friedrichwilken:fix-google-genai-async

Conversation

@friedrichwilken

@friedrichwilken friedrichwilken commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

Context

Closes #152.

langchain-google-genai was pinned to <4.3.7 in #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 ChatGoogleGenerativeAI overrides 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:

AttributeError: 'ChatGoogleGenerativeAI' object has no attribute '_client_cleanup'

Solution: do that async setup in a validator of our own. A new after-validator _register_client_cleanup on ChatGoogleGenerativeAI wraps the injected client in upstream's _ClientCleanup, which is what async_client and aclose() read. The override itself has to stay because upstream overwrites self.client unconditionally. Embeddings are untouched; upstream's embeddings have no such setup.

_ClientCleanup is 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.lock regenerated (only that package changes), stale pin in README_sphynx.md updated.

Testing

  • Added test_async_client_available: asserts async_client resolves and aclose() completes, with a mocked proxy client. Fails on 4.4.0 without the fix, passes with it.
  • Live async integration tests (TestAsyncGoogleGenerativeAI) not run locally (no working AI Core credentials at hand). They exercise exactly this path and run in the CI integration job.

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
@cla-assistant

cla-assistant Bot commented Sep 24, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@alpkom
alpkom merged commit c4f4c64 into SAP:main Sep 25, 2026
17 checks passed
@alpkom

alpkom commented Sep 25, 2026

Copy link
Copy Markdown
Contributor

I've tested this end-to-end explicitly, and it works just fine.
Thanks for the contribution @friedrichwilken !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SAP AI SDK pins langchain-google-genai to patch level 4.3.6

2 participants