File tree Expand file tree Collapse file tree 1 file changed +34
-0
lines changed Expand file tree Collapse file tree 1 file changed +34
-0
lines changed Original file line number Diff line number Diff line change @@ -104,6 +104,40 @@ print(Settings().model_dump())
104
104
105
105
Check the [ Environment variable names documentation] ( #environment-variable-names ) for more information.
106
106
107
+ ## Validation of default values
108
+
109
+ Unlike pydantic ` BaseModel ` , default values of ` BaseSettings ` fields are validated by default.
110
+ You can disable this behaviour by setting ` validate_default=False ` either in ` model_config `
111
+ or on field level by ` Field(validate_default=False) ` :
112
+
113
+ ``` py
114
+ from pydantic import Field
115
+
116
+ from pydantic_settings import BaseSettings, SettingsConfigDict
117
+
118
+
119
+ class Settings (BaseSettings ):
120
+ model_config = SettingsConfigDict(validate_default = False )
121
+
122
+ # default won't be validated
123
+ foo: int = ' test'
124
+
125
+
126
+ print (Settings())
127
+ # > foo='test'
128
+
129
+
130
+ class Settings1 (BaseSettings ):
131
+ # default won't be validated
132
+ foo: int = Field(' test' , validate_default = False )
133
+
134
+
135
+ print (Settings1())
136
+ # > foo='test'
137
+ ```
138
+
139
+ Check the [ Validation of default values] ( validators.md#validation-of-default-values ) for more information.
140
+
107
141
## Environment variable names
108
142
109
143
By default, the environment variable name is the same as the field name.
You can’t perform that action at this time.
0 commit comments