11'''Base class for all Rune type classes'''
22import logging
33import importlib
4+ import copy
45import json
56from typing import get_args , get_origin , Any , Literal
67from typing_extensions import Self
@@ -177,7 +178,7 @@ def rune_deserialize(cls,
177178 rune_data : str | dict [str , Any ],
178179 validate_model : bool = True ,
179180 check_rune_constraints : bool = True ,
180- strict : bool = True ,
181+ strict : bool = False ,
181182 raise_validation_errors : bool = True ) -> BaseModel :
182183 # pylint: disable=line-too-long
183184 '''Rune compliant deserialization
@@ -194,7 +195,7 @@ def rune_deserialize(cls,
194195 deserialization. Defaults to True.
195196
196197 `strict (bool, optional):` Perform strict attribute validation.
197- Defaults to True .
198+ Defaults to False .
198199
199200 `raise_validation_errors (bool, optional):` Raise an exception in
200201 case a validation error has occurred. Defaults to True.
@@ -203,14 +204,20 @@ def rune_deserialize(cls,
203204 `BaseModel:` The Rune model.
204205 '''
205206 if isinstance (rune_data , str ):
206- rune_data = json .loads (rune_data )
207+ rune_dict = json .loads (rune_data )
208+ # NOTE: json.loads will not create the right atomic types
209+ # (e.g. date, datetime, time etc) and the strict model validate
210+ # will not attempt to convert them.
211+ strict = False
207212 elif not isinstance (rune_data , dict ):
208213 raise ValueError (f'rune_data is of type { type (rune_data )} , '
209214 'alas it has to be either dict or str!' )
210- rune_data .pop ('@version' , None )
211- rune_data .pop ('@model' , None )
212- rune_cls = cls ._type_to_cls (rune_data )
213- model = rune_cls .model_validate (rune_data , strict = strict )
215+ else :
216+ rune_dict = copy .deepcopy (rune_data )
217+ rune_dict .pop ('@version' , None )
218+ rune_dict .pop ('@model' , None )
219+ rune_cls = cls ._type_to_cls (rune_dict )
220+ model = rune_cls .model_validate (rune_dict , strict = strict )
214221 model .resolve_references (ignore_dangling = False , recurse = True )
215222 if validate_model :
216223 model .validate_model (check_rune_constraints = check_rune_constraints ,
0 commit comments