From 813e3fc6c2b15188c949143c6f5b8d0e11063dd0 Mon Sep 17 00:00:00 2001 From: olaughter Date: Thu, 22 Aug 2024 15:28:04 +0100 Subject: [PATCH] Add model methods to match backend duplicate model The backend has an identical version of this model except for the additional methods. This makes it so we'll be able to switch out the backend model for this one (and therefore only update in one place) --- src/cpr_sdk/pipeline_general_models.py | 17 ++++++++++++++++- src/cpr_sdk/version.py | 2 +- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/cpr_sdk/pipeline_general_models.py b/src/cpr_sdk/pipeline_general_models.py index 195745f..7096e68 100644 --- a/src/cpr_sdk/pipeline_general_models.py +++ b/src/cpr_sdk/pipeline_general_models.py @@ -2,7 +2,7 @@ from enum import Enum from typing import Mapping, Any, List, Optional, Sequence, Union -from pydantic import BaseModel, model_validator +from pydantic import BaseModel, field_validator, model_validator Json = dict[str, Any] @@ -54,6 +54,21 @@ def convert_publication_ts_to_date(self): return self + @field_validator("type", mode="before") + @classmethod + def none_to_empty_string(cls, value): + """If the value is None, will convert to an empty string""" + return "" if value is None else value + + def to_json(self) -> Mapping[str, Any]: + """Provide a serialisable version of the model""" + + json_dict = self.model_dump() + json_dict["publication_ts"] = ( + self.publication_ts.isoformat() if self.publication_ts is not None else None + ) + return json_dict + class InputData(BaseModel): """Expected input data containing RDS state.""" diff --git a/src/cpr_sdk/version.py b/src/cpr_sdk/version.py index 850f722..19cdcb8 100644 --- a/src/cpr_sdk/version.py +++ b/src/cpr_sdk/version.py @@ -1,5 +1,5 @@ _MAJOR = "1" -_MINOR = "1" +_MINOR = "2" _PATCH = "10" _SUFFIX = ""