checkpoint: Avoid changes to pydantic models breaking deserialization while still relying on pydantic's type coercion

This commit is contained in:
Nuno Campos
2024-08-30 13:28:32 -07:00
parent c761b80970
commit 5db13dffbe
@@ -51,13 +51,9 @@ class JsonPlusSerializer(SerializerProtocol):
if isinstance(obj, Serializable):
return obj.to_json()
elif hasattr(obj, "model_dump") and callable(obj.model_dump):
return self._encode_constructor_args(
obj.__class__, method="model_construct", kwargs=obj.model_dump()
)
return self._encode_constructor_args(obj.__class__, kwargs=obj.model_dump())
elif hasattr(obj, "dict") and callable(obj.dict):
return self._encode_constructor_args(
obj.__class__, method="construct", kwargs=obj.dict()
)
return self._encode_constructor_args(obj.__class__, kwargs=obj.dict())
elif isinstance(obj, pathlib.Path):
return self._encode_constructor_args(pathlib.Path, args=obj.parts)
elif isinstance(obj, re.Pattern):
@@ -150,7 +146,7 @@ class JsonPlusSerializer(SerializerProtocol):
return method(**value["kwargs"])
else:
return method()
except (ImportError, AttributeError, TypeError):
except Exception:
return None
return LC_REVIVER(value)