pydantic / pydantic-settings

Settings management using pydantic
https://docs.pydantic.dev/latest/usage/pydantic_settings/
MIT License
593 stars 61 forks source link

Unable to create config with submodel named "api" #278

Closed voodoo11 closed 4 months ago

voodoo11 commented 5 months ago

When attempting to create a config with a submodel named "api", an error occurs:

pydantic_settings.sources.SettingsError: error parsing value for field "api" from source "EnvSettingsSource"

How to reproduce:

from pydantic import BaseModel
from pydantic_settings import BaseSettings

class ApiConfig(BaseModel):
    foo: str

class Config(BaseSettings):
    api: ApiConfig = ApiConfig()

Config()

Changing submodel name fixes the problem.

hramezani commented 4 months ago

@voodoo11 Sorry for the late response. sub model name shouldn't make any problem. probably there is an env variable with the name api in your environment.

voodoo11 commented 4 months ago

Thanks @hramezani.