diff --git a/pydantic_ai_slim/pydantic_ai/providers/google.py b/pydantic_ai_slim/pydantic_ai/providers/google.py index d0de4bcc4f..a4ba0c5a3b 100644 --- a/pydantic_ai_slim/pydantic_ai/providers/google.py +++ b/pydantic_ai_slim/pydantic_ai/providers/google.py @@ -219,5 +219,6 @@ class _NonClosingApiClient(BaseApiClient): async def aclose(self) -> None: # The original implementation also calls `await self._async_httpx_client.aclose()`, but we don't want to close our `cached_async_http_client` or the one the user passed in. # TODO: Remove once https://github.com/googleapis/python-genai/issues/1566 is solved. - if self._aiohttp_session: - await self._aiohttp_session.close() # pragma: no cover + session = getattr(self, '_aiohttp_session', None) + if session is not None: + await session.close() # pragma: no cover