SerializableSchema should check if its values can be serialized, so that it doesn't break when used in a union with a base type or schema that isn't a SerializableSchema

This commit is contained in:
Gwendolyn 2023-12-11 14:07:41 +01:00
parent 058ff148cf
commit d0d18fcae2

View file

@ -41,7 +41,7 @@ class SerializableSchema(Schema):
@classmethod
def _run_root_validator(cls, values: Any, handler: ModelWrapValidatorHandler[Schema], info: ValidationInfo) -> Any:
""" overwriting this, we need to call serialize to get the correct data """
if not isinstance(values, dict):
if hasattr(values, 'serialize') and callable(values.serialize):
values = values.serialize()
return handler(values)