File tree Expand file tree Collapse file tree 1 file changed +11
-1
lines changed Expand file tree Collapse file tree 1 file changed +11
-1
lines changed Original file line number Diff line number Diff line change @@ -383,10 +383,20 @@ Because python-dotenv is used to parse the file, bash-like semantics such as `ex
383
383
(depending on your OS and environment) may allow your dotenv file to also be used with ` source ` ,
384
384
see [ python-dotenv's documentation] ( https://saurabh-kumar.com/python-dotenv/#usages ) for more details.
385
385
386
- Pydantic settings consider ` extra ` config in case of dotenv file. It means if you set the ` extra=forbid `
386
+ Pydantic settings consider ` extra ` config in case of dotenv file. It means if you set the ` extra=forbid ` ( * default * )
387
387
on ` model_config ` and your dotenv file contains an entry for a field that is not defined in settings model,
388
388
it will raise ` ValidationError ` in settings construction.
389
389
390
+ For compatibility with pydantic 1.x BaseSettings you should use ` extra=ignore ` :
391
+ ``` py
392
+ from pydantic_settings import BaseSettings, SettingsConfigDict
393
+
394
+
395
+ class Settings (BaseSettings ):
396
+ model_config = SettingsConfigDict(env_file = ' .env' , extra = ' ignore' )
397
+ ```
398
+
399
+
390
400
## Secrets
391
401
392
402
Placing secret values in files is a common pattern to provide sensitive configuration to an application.
You can’t perform that action at this time.
0 commit comments