From 8bfb5b1f9fde8698ff1278c5264e145b40d4380b Mon Sep 17 00:00:00 2001 From: DABH Date: Wed, 15 Jul 2026 23:42:56 -0500 Subject: [PATCH 1/3] Fix google_genai type checking under google-genai 2.12.0 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit google-genai 2.12.0 exports two Interaction names from google.genai.interactions: the interaction resource class and a TypeAliasType over the trigger-request variants. Runtime star-import ordering deliberately binds the name to the resource class, but type checkers resolve it to the alias, which cannot be used with isinstance and lacks the resource fields — mypy fails with 34 errors (first seen on test-latest-deps when 2.12.0 released). Add a _compat shim that keeps the runtime binding on the public path (the imported object is unchanged — identity-verified against 2.10.0 and 2.12.0) and points the static view at the class's defining module, which is the same location in both versions. Redirect the three import sites through the shim. Verified with mypy, pyright, and basedpyright plus the google_genai test suite (62 passed) under both google-genai 2.10.0 (locked) and 2.12.0 (latest). --- temporalio/contrib/google_genai/_compat.py | 26 +++++++++++++++++++ .../contrib/google_genai/_gemini_activity.py | 2 +- .../google_genai/_temporal_interactions.py | 3 ++- tests/contrib/google_genai/test_gemini.py | 2 +- 4 files changed, 30 insertions(+), 3 deletions(-) create mode 100644 temporalio/contrib/google_genai/_compat.py diff --git a/temporalio/contrib/google_genai/_compat.py b/temporalio/contrib/google_genai/_compat.py new file mode 100644 index 000000000..e3bf3d95a --- /dev/null +++ b/temporalio/contrib/google_genai/_compat.py @@ -0,0 +1,26 @@ +"""Version-compatibility shims for the ``google-genai`` SDK. + +Single home for workarounds that keep the plugin importable and +type-checkable across the supported ``google-genai`` range; remove entries +as upstream fixes land. +""" + +from __future__ import annotations + +from typing import TYPE_CHECKING + +if TYPE_CHECKING: + # google-genai 2.12.0 exports two ``Interaction`` names: the interaction + # resource class and a ``TypeAliasType`` over the trigger-request + # variants. At runtime the resource class deliberately wins the + # star-import ordering in ``google.genai.interactions`` (see the comment + # there), but type checkers resolve the name to the alias — which cannot + # be used with ``isinstance`` and lacks the resource fields (``id``, + # ``status``, ...). Bind the static view to the class's defining module + # (the same location in 2.10.x); the runtime binding stays on the public + # path, so behavior is unchanged. + from google.genai._gaos.types.interactions.interaction import Interaction +else: + from google.genai.interactions import Interaction + +__all__ = ["Interaction"] diff --git a/temporalio/contrib/google_genai/_gemini_activity.py b/temporalio/contrib/google_genai/_gemini_activity.py index 2e92c56a1..496bbf1ab 100644 --- a/temporalio/contrib/google_genai/_gemini_activity.py +++ b/temporalio/contrib/google_genai/_gemini_activity.py @@ -17,11 +17,11 @@ from google.genai import Client as GeminiClient from google.genai import errors as genai_errors from google.genai import types -from google.genai.interactions import Interaction from google.genai.types import HttpOptions from google.genai.types import HttpResponse as SdkHttpResponse from temporalio import activity +from temporalio.contrib.google_genai._compat import Interaction from temporalio.contrib.google_genai._models import ( _GeminiApiRequest, _GeminiApiResponse, diff --git a/temporalio/contrib/google_genai/_temporal_interactions.py b/temporalio/contrib/google_genai/_temporal_interactions.py index b5eb2edc0..54d8353cd 100644 --- a/temporalio/contrib/google_genai/_temporal_interactions.py +++ b/temporalio/contrib/google_genai/_temporal_interactions.py @@ -20,9 +20,10 @@ from typing import Any, cast import pydantic -from google.genai.interactions import Interaction, InteractionSSEEvent +from google.genai.interactions import InteractionSSEEvent from temporalio import workflow as temporal_workflow +from temporalio.contrib.google_genai._compat import Interaction from temporalio.contrib.google_genai._models import ( _GeminiInteractionIdRequest, _GeminiInteractionRequest, diff --git a/tests/contrib/google_genai/test_gemini.py b/tests/contrib/google_genai/test_gemini.py index 543ad648c..0881f63b3 100644 --- a/tests/contrib/google_genai/test_gemini.py +++ b/tests/contrib/google_genai/test_gemini.py @@ -32,7 +32,6 @@ from google.genai import types from google.genai.interactions import ( Agent, # pyright: ignore[reportPrivateImportUsage] - Interaction, InteractionSSEEvent, ) from google.genai.types import HttpResponse as SdkHttpResponse @@ -45,6 +44,7 @@ GoogleGenAIPlugin, activity_as_tool, ) +from temporalio.contrib.google_genai._compat import Interaction from temporalio.contrib.google_genai._models import ( _GeminiApiRequest, _GeminiApiResponse, From 8301d806d3a6d5f0756b1ff449778cad699ffae8 Mon Sep 17 00:00:00 2001 From: David Hyde Date: Wed, 15 Jul 2026 23:50:10 -0500 Subject: [PATCH 2/3] Clarify comments --- temporalio/contrib/google_genai/_compat.py | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/temporalio/contrib/google_genai/_compat.py b/temporalio/contrib/google_genai/_compat.py index e3bf3d95a..be857c907 100644 --- a/temporalio/contrib/google_genai/_compat.py +++ b/temporalio/contrib/google_genai/_compat.py @@ -12,15 +12,12 @@ if TYPE_CHECKING: # google-genai 2.12.0 exports two ``Interaction`` names: the interaction # resource class and a ``TypeAliasType`` over the trigger-request - # variants. At runtime the resource class deliberately wins the - # star-import ordering in ``google.genai.interactions`` (see the comment - # there), but type checkers resolve the name to the alias — which cannot - # be used with ``isinstance`` and lacks the resource fields (``id``, - # ``status``, ...). Bind the static view to the class's defining module - # (the same location in 2.10.x); the runtime binding stays on the public - # path, so behavior is unchanged. + # variants. At runtime we get the resource class but type checkers + # resolve to the alias which causes failures (the alias has no ``id``, + # etc.). Force the type checker to see the right import here. from google.genai._gaos.types.interactions.interaction import Interaction else: + # < 2.12.0 has the expected behavior / only one exported ``Interaction`` from google.genai.interactions import Interaction __all__ = ["Interaction"] From 33e5acfc6c4ba8908e1b8228900f01575f6e1e87 Mon Sep 17 00:00:00 2001 From: David Hyde Date: Wed, 15 Jul 2026 23:53:06 -0500 Subject: [PATCH 3/3] Correct comments --- temporalio/contrib/google_genai/_compat.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/temporalio/contrib/google_genai/_compat.py b/temporalio/contrib/google_genai/_compat.py index be857c907..6613e2b9c 100644 --- a/temporalio/contrib/google_genai/_compat.py +++ b/temporalio/contrib/google_genai/_compat.py @@ -14,10 +14,11 @@ # resource class and a ``TypeAliasType`` over the trigger-request # variants. At runtime we get the resource class but type checkers # resolve to the alias which causes failures (the alias has no ``id``, - # etc.). Force the type checker to see the right import here. + # etc.). Force the type checker to see the class' defining module (in + # the same location in 2.10 and 2.12). from google.genai._gaos.types.interactions.interaction import Interaction else: - # < 2.12.0 has the expected behavior / only one exported ``Interaction`` + # At runtime, Interaction resolves properly for 2.10 and 2.12 from google.genai.interactions import Interaction __all__ = ["Interaction"]