googleapis / googleapis/python-aiplatform

`TypeError: Plain typing.TypeAlias is not valid as type argument` in vertexai/_genai/_agent_engines_utils.py on Python 3.10

Abierto
#6,404 0 comentarios 1 reacción 0 asignados Ver en GitHub
api: vertex-ai
Lenguaje dominante
Python
Estrellas
905
Forks
465
Merge medio
1 d 13 h
PR fusionados (30 d)
44

Descripción

#### 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 "", line 1050, in _gcd_import
File "", line 1027, in _find_and_load
File "", line 1006, in _find_and_load_unlocked
File "", line 688, in _load_unlocked
File "", line 883, in exec_module
File "", 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
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
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

```python
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:
```toml
google-cloud-aiplatform = "1.135.0"
```

Guía de contribución

Abrir la guía de contribución

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.