From d13416ed9b18819eb278379d22a9b7fc07465171 Mon Sep 17 00:00:00 2001 From: Niels Nuyttens Date: Tue, 9 Jul 2024 21:33:06 +0200 Subject: [PATCH 1/2] Deal with Pydantic protected namespace conflicts --- nannyml/io/db/entities.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/nannyml/io/db/entities.py b/nannyml/io/db/entities.py index f282b31ec..7800beaca 100644 --- a/nannyml/io/db/entities.py +++ b/nannyml/io/db/entities.py @@ -11,6 +11,7 @@ from datetime import datetime from typing import List, Optional +from pydantic import ConfigDict from sqlmodel import Field, Relationship, SQLModel @@ -42,6 +43,11 @@ class Run(SQLModel, table=True): # type: ignore[call-arg] Stored in the ``run`` table. """ + # Ignore clash of `model_id` field name with default protected namespace `model_` + # See: https://github.com/pydantic/pydantic/discussions/7121 + # Better solution using `alias` is not possible due to SQLModel issue + model_config = ConfigDict(protected_namespaces=()) + #: Foreign key in all ``metric`` tables id: Optional[int] = Field(default=None, primary_key=True) @@ -61,6 +67,11 @@ class Metric(SQLModel): Base ``Metric`` definition. """ + # Ignore clash of `model_id` field name with default protected namespace `model_` + # See: https://github.com/pydantic/pydantic/discussions/7121 + # Better solution using `alias` is not possible due to SQLModel issue + model_config = ConfigDict(protected_namespaces=()) + #: The technical identifier for this database row id: Optional[int] = Field(default=None, primary_key=True) From c87abfe6d701784d8fd8f24bfd929124d935680e Mon Sep 17 00:00:00 2001 From: Niels Nuyttens Date: Tue, 9 Jul 2024 21:33:34 +0200 Subject: [PATCH 2/2] Add defaults for optional configuration properties (changed default behavior of Pydantic 2) --- nannyml/config.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/nannyml/config.py b/nannyml/config.py index 2e8e4743c..170d86e82 100644 --- a/nannyml/config.py +++ b/nannyml/config.py @@ -88,11 +88,11 @@ def _parse_thresholds(cls, value: Dict[str, Any]): class Config(BaseModel): - input: Optional[InputConfig] + input: Optional[InputConfig] = None calculators: List[CalculatorConfig] - scheduling: Optional[SchedulingConfig] + scheduling: Optional[SchedulingConfig] = None - ignore_errors: Optional[bool] + ignore_errors: Optional[bool] = None @classmethod @lru_cache(maxsize=1)