You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In google-genai 1.51.0 on Python 3.10, calling client.models.list() or instantiating any Pydantic model under google.genai.types (e.g., UserContent) results in the following error:
TypeError: issubclass() arg 1 must be a class
Full traceback:
[22:48:50] [Core] [ERRO] [routes.config:613]: Traceback (most recent call last):
File "/Users/moonshot/AstrBot/astrbot/dashboard/routes/config.py", line 606, in get_provider_model_list
models = await provider.get_models()
File "/Users/moonshot/AstrBot/astrbot/core/provider/sources/gemini_source.py", line 726, in get_models
models = await self.client.models.list()
File "/Users/moonshot/AstrBot/.venv/lib/python3.10/site-packages/google/genai/models.py", line 7402, in list
await self._list(config=config),
File "/Users/moonshot/AstrBot/.venv/lib/python3.10/site-packages/google/genai/models.py", line 6550, in _list
response = await self._api_client.async_request(
File "/Users/moonshot/AstrBot/.venv/lib/python3.10/site-packages/google/genai/_api_client.py", line 1380, in async_request
return SdkHttpResponse(headers=result.headers, body=response_body)
File "/Users/moonshot/AstrBot/.venv/lib/python3.10/site-packages/pydantic/main.py", line 214, in __init__
validated_self = self.__pydantic_validator__.validate_python(data, self_instance=self)
File "/Users/moonshot/AstrBot/.venv/lib/python3.10/site-packages/google/genai/_common.py", line 591, in _check_field_type_mismatches
issubclass(expected_type, pydantic.BaseModel) and
File "/Users/moonshot/.local/share/uv/python/cpython-3.10.16-macos-aarch64-none/lib/python3.10/abc.py", line 123, in __subclasscheck__
return _abc_subclasscheck(cls, subclass)
TypeError: issubclass() arg 1 must be a class
Root Cause
This issue is caused by a well-known difference in issubclass() behavior between Python 3.10 and Python 3.11+, specifically when the first argument is a GenericAlias, such as:
dict[str, str]
list[int]
tuple[str, int]
In Python 3.10, these types are not treated as real classes and trigger:
TypeError: issubclass() arg 1 must be a class
This happens inside the google/genai/_common.py validator:
if (isinstance(expected_type, type) andissubclass(expected_type, pydantic.BaseModel) andisinstance(value, pydantic.BaseModel) andnotisinstance(value, expected_type)):
When expected_type is dict[str, str], the issubclass() call raises a TypeError on Python 3.10.
This is a Python bug, not specific to google-genai.
In
google-genai 1.51.0onPython 3.10, callingclient.models.list()or instantiating any Pydantic model undergoogle.genai.types(e.g., UserContent) results in the following error:TypeError: issubclass() arg 1 must be a classFull traceback:
Root Cause
This issue is caused by a well-known difference in issubclass() behavior between Python 3.10 and Python 3.11+, specifically when the first argument is a GenericAlias, such as:
In Python 3.10, these types are not treated as real classes and trigger:
TypeError: issubclass() arg 1 must be a classThis happens inside the google/genai/_common.py validator:
When expected_type is dict[str, str], the issubclass() call raises a TypeError on Python 3.10.
This is a Python bug, not specific to google-genai.
References:
Behavior difference example
Python 3.10 (fails):
>>> import pydantic >>> issubclass(dict[str, str], pydantic.BaseModel) Traceback (most recent call last): ... TypeError: issubclass() arg 1 must be a classPython 3.11+ (works correctly):
Environment details
Steps to reproduce
await AsyncClient.models.list(), orgoogle.genai.types(e.g., UserContent)