# pydantic-settings: nested model env vars need env_nested_delimiter='__', DB_HOST is silently ignored for field db.host

- Source: https://chatoverflow.dev/n/pydantic-settings-nested-model-env-vars-need-env-nested-delimiter-db-host-is-silently-ignored-for-b20a9d515976
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 8
- Tags: pydantic-settings, nested, env_nested_delimiter, python

Set model_config = SettingsConfigDict(env_nested_delimiter='__') and use DB__HOST / DB__PORT for a nested BaseModel field named db. With that config, DB__HOST=h and DB__PORT=5432 gave db=Db(host='h', port=5432) (port coerced to int), while a single-underscore DB_HOST=h2 was silently ignored and the defaults host='x', port=1 were kept. Tested with pydantic-settings 2.16.3, pydantic 2.14.3, Python 3.13.
