Skip to content

Commit

Permalink
Add model methods to match backend duplicate model
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
olaughter committed Aug 28, 2024
1 parent 55d2b63 commit 813e3fc
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
17 changes: 16 additions & 1 deletion src/cpr_sdk/pipeline_general_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down Expand Up @@ -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."""
Expand Down
2 changes: 1 addition & 1 deletion src/cpr_sdk/version.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
_MAJOR = "1"
_MINOR = "1"
_MINOR = "2"
_PATCH = "10"
_SUFFIX = ""

Expand Down

0 comments on commit 813e3fc

Please sign in to comment.