-
-
Notifications
You must be signed in to change notification settings - Fork 103
Closed
Labels
bugSomething isn't workingSomething isn't workingduplicateThis issue or pull request already existsThis issue or pull request already exists
Description
After upgrading to version 2.5.1 I still of TypeError when init class with list[type] it will raise TypeError: issubclass() arg 1 must be a class
which is supposed to be fixed
Code
from pydantic_settings import BaseSettings
class TestConfig(BaseSettings):
cors_origins: list[str] | None = ["*"]
cors_headers: list[str] | None = ["*"]
cors_methods: list[str] | None = ["*"]
def main():
config = TestConfig()
print(config.cors_origins)
if __name__ == "__main__":
main()
Traceback
Traceback (most recent call last):
File "venv/lib/python3.10/site-packages/pydantic_settings/sources.py", line 538, in __call__
field_value, field_key, value_is_complex = self.get_field_value(field, field_name)
File "venv/lib/python3.10/site-packages/pydantic_settings/sources.py", line 714, in get_field_value
for field_key, env_name, value_is_complex in self._extract_field_info(field, field_name):
File "venv/lib/python3.10/site-packages/pydantic_settings/sources.py", line 443, in _extract_field_info
elif origin_is_union(get_origin(field.annotation)) and _union_is_complex(field.annotation, field.metadata):
File "venv/lib/python3.10/site-packages/pydantic_settings/sources.py", line 2152, in _union_is_complex
return any(_annotation_is_complex(arg, metadata) for arg in get_args(annotation))
File "venv/lib/python3.10/site-packages/pydantic_settings/sources.py", line 2152, in <genexpr>
return any(_annotation_is_complex(arg, metadata) for arg in get_args(annotation))
File "venv/lib/python3.10/site-packages/pydantic_settings/sources.py", line 2118, in _annotation_is_complex
if annotation is not None and inspect.isclass(annotation) and issubclass(annotation, RootModel):
File "/usr/lib/python3.10/abc.py", line 123, in __subclasscheck__
return _abc_subclasscheck(cls, subclass)
TypeError: issubclass() arg 1 must be a class
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "test.py", line 29, in <module>
main()
File "test.py", line 25, in main
config = TestConfig()
File "venv/lib/python3.10/site-packages/pydantic_settings/main.py", line 153, in __init__
**__pydantic_self__._settings_build_values(
File "venv/lib/python3.10/site-packages/pydantic_settings/main.py", line 357, in _settings_build_values
source_state = source()
File "venv/lib/python3.10/site-packages/pydantic_settings/sources.py", line 540, in __call__
raise SettingsError(
pydantic_settings.sources.SettingsError: error getting value for field "cors_origins" from source "EnvSettingsSource"
Here is my log from pip list
$ pip list | grep pydantic
pydantic 2.8.2
pydantic_core 2.20.1
pydantic-extra-types 2.9.0
pydantic-settings 2.5.1
[notice] A new release of pip is available: 23.2.1 -> 24.2
[notice] To update, run: pip install --upgrade pip
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't workingduplicateThis issue or pull request already existsThis issue or pull request already exists