Repository navigation
Conversation
…-framework spans When the agent-framework chat-generation flag is set, the async generate_content wrappers returned the wrapped coroutine without awaiting it, so callers received a coroutine instead of a GenerateContentResponse (or an async iterator for the stream variant). Await the wrapped call on that path, matching the OpenAI and Anthropic async wrappers. Fixes getsentry#8414
Contributor
PR risk: mediumFor commit Main concerns: reach. This label is a hint for reviewers, not an approval. |
This branch has not been deployed
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.
Fixes #8414. When the agent-framework chat-generation flag is set (e.g. by PydanticAIIntegration), the async
generate_contentwrappers inGoogleGenAIIntegrationreturned the wrapped coroutine without awaiting it, so callers received a coroutine instead of aGenerateContentResponse(or an async iterator for the stream variant):AttributeError: 'coroutine' object has no attribute 'candidates'plus a never-awaited coroutine warning. The flag is only set when the agent-framework chat span is a real sampled Span, so in production the failure is intermittent. Both wrappers nowreturn await f(self, *args, **kwargs)on that path, matching the OpenAI and Anthropic async wrappers.Why not duplicating: no open PR addresses #8414 (checked PR search by symbol
new_async_generate_content is:pr— 0 results — and the issue's closing-PR references at verification); the reporter only suggests the fix and holds no patch.Tests run: standalone repro with a real
genai.Clientand mocked HTTP (pre-fix returns a coroutine and raisesAttributeError; post-fix returns the response with the expected text); 2 new regression tests intests/integrations/google_genai/test_google_genai.py(async non-streaming + async streaming, both entering the real_AgentFrameworkChatGenerationContext) — both fail on the pre-fix code and pass with the fix; full test filetests/integrations/google_genai/test_google_genai.py: 101 passed, 1 skipped.ruff checkandruff formatclean;mypy sentry_sdk tests: no issues in 502 source files. No live Google API or pydantic-ai agent run was used; the repro and tests mock the HTTP layer exactly as the file's existing tests do.AI assistance was used to implement this fix; the change was reviewed line-by-line and the reproduction and tests were run locally before requesting review.
Note: the async embed wrapper has no such early-return branch and is unchanged, as are both sync wrappers.