workaround for default value

This commit is contained in:
Jörn-Michael Miehe 2023-08-30 23:28:04 +00:00
parent 9d754ad4e8
commit a8627bad84
3 changed files with 32 additions and 11 deletions

4
.vscode/launch.json vendored
View file

@ -9,6 +9,10 @@
"type": "python",
"request": "launch",
"module": "kiwi_simple_metrics.main",
"env": {
"METRIC_DISK__THRESHOLD": "85", // workaround!
"METRIC_DISK__PARAMS": "[\"/var\", \"/\"]",
},
"justMyCode": true
}
]

View file

@ -24,17 +24,9 @@ class Settings(BaseSettings):
env_nested_delimiter="__",
)
cpu: MetricS = MetricS(
threshold=100,
)
memory: MetricS = MetricS(
threshold=90,
)
disk: ParamMS = ParamMS(
threshold=85,
)
cpu: MetricS = MetricS(threshold=100)
memory: MetricS = MetricS(threshold=90)
disk: ParamMS = ParamMS(threshold=85)
SETTINGS = Settings()

25
min_fail_example.py Normal file
View file

@ -0,0 +1,25 @@
from pydantic import BaseModel
class SubModel(BaseModel):
optional: int = 42
required: str
class Settings(BaseModel):
sub: SubModel = SubModel(required="foo")
sub2: SubModel = SubModel(required="bar")
def main() -> None:
settings = Settings.model_validate({
"sub": {"optional": "69"},
})
# settings = Settings()
print(settings.model_dump())
if __name__ == "__main__":
main()