Skip to content

Commit 3205f81

Browse files
authored
Add note about nested model should inherit BaseModel (#165)
1 parent 4f794c7 commit 3205f81

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

docs/index.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,11 +249,11 @@ from pydantic import BaseModel
249249
from pydantic_settings import BaseSettings, SettingsConfigDict
250250

251251

252-
class DeepSubModel(BaseModel):
252+
class DeepSubModel(BaseModel): # (1)!
253253
v4: str
254254

255255

256-
class SubModel(BaseModel):
256+
class SubModel(BaseModel): # (2)!
257257
v1: str
258258
v2: bytes
259259
v3: int
@@ -276,6 +276,12 @@ print(Settings().model_dump())
276276
"""
277277
```
278278

279+
1. Sub model has to inherit from `pydantic.BaseModel`, Otherwise `pydantic-settings` will initialize sub model,
280+
collects values for sub model fields separately, and you may get unexpected results.
281+
282+
1. Sub model has to inherit from `pydantic.BaseModel`, Otherwise `pydantic-settings` will initialize sub model,
283+
collects values for sub model fields separately, and you may get unexpected results.
284+
279285
`env_nested_delimiter` can be configured via the `model_config` as shown above, or via the
280286
`_env_nested_delimiter` keyword argument on instantiation.
281287

0 commit comments

Comments
 (0)