`TypeError: Plain typing.TypeAlias is not valid as type argument` in vertexai/_genai/_agent_engines_utils.py on Python 3.10
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 55/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Stale
- Tech stack
- google-cloud, python
- Domain
- machine-learning
Research direction
Start in vertexai/_genai/_agent_engines_utils.py at line 289 and review the runtime ADKAgent annotation path. Reproduce the import on Python 3.10 with the affected dependency versions, then verify that importing the module no longer raises the TypeError while the optional google.adk import behavior remains intact.
Written by the indexing model from the issue text.
Description
Environment details
- Python: 3.10.1
- google-cloud-aiplatform: 1.140.0
- google-adk: 1.26.0
- OS: Linux (Kubernetes)
- Buggy versions: 1.136.0, 1.137.0, 1.138.0, 1.139.0, 1.140.0
- Python versions affected: 3.10.x
- Last working version: 1.135.0
Steps to reproduce
Not sure this was encountered while using google adk which has this as a dependency.
Full traceback of error after making a POST request to create a session which triggered this error:
Traceback (most recent call last):
File "/root/.pyenv/versions/3.10/lib/python3.10/site-packages/google/adk/cli/adk_web_server.py", line 660, in _create_session
session = await self.session_service.create_session(
File "/root/.pyenv/versions/3.10/lib/python3.10/site-packages/google/adk/sessions/vertex_ai_session_service.py", line 115, in create_session
api_response = await api_client.agent_engines.sessions.create(
File "/root/.pyenv/versions/3.10/lib/python3.10/site-packages/vertexai/_genai/client.py", line 111, in agent_engines
self._agent_engines = importlib.import_module(
File "/root/.pyenv/versions/3.10.1/lib/python3.10/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 883, in exec_module
File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
File "/root/.pyenv/versions/3.10/lib/python3.10/site-packages/vertexai/_genai/agent_engines.py", line 34, in <module>
from . import _agent_engines_utils
File "/root/.pyenv/versions/3.10/lib/python3.10/site-packages/vertexai/_genai/_agent_engines_utils.py", line 289, in <module>
ADKAgent: Optional[TypeAlias] = BaseAgent
File "/root/.pyenv/versions/3.10.1/lib/python3.10/typing.py", line 311, in inner
return func(*args, **kwds)
File "/root/.pyenv/versions/3.10.1/lib/python3.10/typing.py", line 402, in __getitem__
return self._getitem(self, parameters)
File "/root/.pyenv/versions/3.10.1/lib/python3.10/typing.py", line 528, in Optional
arg = _type_check(parameters, f"{self} requires a single type.")
File "/root/.pyenv/versions/3.10.1/lib/python3.10/typing.py", line 171, in _type_check
raise TypeError(f"Plain {arg} is not valid as type argument")
TypeError: Plain typing.TypeAlias is not valid as type argument
Root Cause
File: vertexai/_genai/_agent_engines_utils.py
Line: 289
if typing.TYPE_CHECKING:
from google.adk.agents import BaseAgent
ADKAgent: TypeAlias = BaseAgent
else:
try:
from google.adk.agents import BaseAgent
ADKAgent: Optional[TypeAlias] = BaseAgent # this is the line causing issues
except (ImportError, AttributeError):
ADKAgent = None # type: ignore[no-redef]
Not sure the syntax Optional[TypeAlias] valid 3.10? Confusing though since I think the syntax is valid unclear why it would cause this runtime error.
Introduced in: https://github.com/googleapis/python-aiplatform/commit/d8cc50dd67
Workaround
Pin to version 1.135.0 or earlier:
google-cloud-aiplatform = "1.135.0"
- Dominant language
- Python
- Stars
- 907
- Forks
- 467
- Avg merge
- 1d 8h
- Merged PRs (30d)
- 40
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from googleapis/python-aiplatform
-
api: vertex-ai
Difficulty 1/5 Under an hour Newbie friendliness 85/100
googleapis/python-aiplatform#7132 ·
-
api: vertex-ai
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
googleapis/python-aiplatform#7097 ·
-
CustomContainerTrainingJob.run drops max_wait_duration=0 instead of requesting indefinite DWS wait Openapi: vertex-ai
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
googleapis/python-aiplatform#7067 · 1 comment ·
-
api: vertex-ai
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
googleapis/python-aiplatform#6877 ·
-
api: vertex-ai
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
googleapis/python-aiplatform#6865 · 1 comment ·
All issues in googleapis/python-aiplatform
Similar issues
-
area: harness bug status: needs-triage
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
Human-Agent-Society/reef#625 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
-
Difficulty 1/5 Under an hour Newbie friendliness 80/100
learningequality/kolibri#15351 · 2 comments ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
-
Name consistency Open
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
eellak/triplestore#65 · 1 comment ·