From a8627bad842190575b171be24f129b060e625db0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn-Michael=20Miehe?= <40151420+ldericher@users.noreply.github.com> Date: Wed, 30 Aug 2023 23:28:04 +0000 Subject: [PATCH] workaround for default value --- .vscode/launch.json | 4 ++++ kiwi_simple_metrics/settings.py | 14 +++----------- min_fail_example.py | 25 +++++++++++++++++++++++++ 3 files changed, 32 insertions(+), 11 deletions(-) create mode 100644 min_fail_example.py diff --git a/.vscode/launch.json b/.vscode/launch.json index 437feb4..b95c351 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -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 } ] diff --git a/kiwi_simple_metrics/settings.py b/kiwi_simple_metrics/settings.py index 40a2543..2ac035a 100644 --- a/kiwi_simple_metrics/settings.py +++ b/kiwi_simple_metrics/settings.py @@ -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() diff --git a/min_fail_example.py b/min_fail_example.py new file mode 100644 index 0000000..c812183 --- /dev/null +++ b/min_fail_example.py @@ -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()