|
5 | 5 | import dataclasses |
6 | 6 | import hashlib |
7 | 7 | import itertools |
| 8 | +import json |
8 | 9 | import os |
9 | 10 | import posixpath |
10 | 11 | import time |
|
50 | 51 | MlemError, |
51 | 52 | MlemObjectNotFound, |
52 | 53 | MlemObjectNotSavedError, |
| 54 | + SerializationError, |
53 | 55 | WrongABCType, |
54 | 56 | WrongMetaSubType, |
55 | 57 | WrongMetaType, |
@@ -91,9 +93,19 @@ class Config: |
91 | 93 | object_type: ClassVar[str] |
92 | 94 | location: Optional[Location] = None |
93 | 95 | """MlemObject location [transient]""" |
94 | | - params: Dict[str, str] = {} |
| 96 | + params: Dict[str, Any] = {} |
95 | 97 | """Arbitrary map of additional parameters""" |
96 | 98 |
|
| 99 | + @validator("params") |
| 100 | + def params_are_serializable( # pylint: disable=no-self-argument |
| 101 | + cls, value # noqa: B902 |
| 102 | + ): |
| 103 | + try: |
| 104 | + json.dumps(value) |
| 105 | + except TypeError as e: |
| 106 | + raise SerializationError(f"Can't serialize object: {value}") from e |
| 107 | + return value |
| 108 | + |
97 | 109 | @property |
98 | 110 | def loc(self) -> Location: |
99 | 111 | if self.location is None: |
@@ -751,7 +763,7 @@ def from_obj( |
751 | 763 | model: Any, |
752 | 764 | sample_data: Any = None, |
753 | 765 | methods_sample_data: Dict[str, Any] = None, |
754 | | - params: Dict[str, str] = None, |
| 766 | + params: Dict[str, Any] = None, |
755 | 767 | preprocess: Union[Any, Dict[str, Any]] = None, |
756 | 768 | postprocess: Union[Any, Dict[str, Any]] = None, |
757 | 769 | ) -> "MlemModel": |
@@ -931,7 +943,7 @@ def data(self): |
931 | 943 | def from_data( |
932 | 944 | cls, |
933 | 945 | data: Any, |
934 | | - params: Dict[str, str] = None, |
| 946 | + params: Dict[str, Any] = None, |
935 | 947 | ) -> "MlemData": |
936 | 948 | data_type = DataType.create( |
937 | 949 | data, |
|
0 commit comments