Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def load(self, data: typing.Any) -> typing.Any:
"""
Use schema to validate given data and return dataclass instance.
If validation fail, raise InputValidationException
:param data: data to validate and process
:return: schema dataclass instance
"""
# Prevent serpyco error when Rrequest context give us a MultiDictProxy
if isinstance(data, (MultiDictProxy, MultiDict)):
data = dict(data)
try:
return self.serializer.load(data)
except ValidationError as exc:
raise ValidationException("Error when loading: {}".format(exc.args[0])) from exc
except Exception as exc:
raise ValidationException(
'Unknown error when serpyco load: "{}": "{}"'.format(type(exc).__name__, str(exc))
) from exc