def __call__(self, value): value, errors = self.schema.dump(value) if errors: raise InvalidTypeData( 'Invalid {0} passed in'.format(self.schema.__class__.__name__), errors) return value
def marshmallow_type(input_data): result, errors = marshmallow.loads(input_data) if isinstance( input_data, str) else marshmallow.load(input_data) if errors: raise InvalidTypeData( 'Invalid {0} passed in'.format(marshmallow.__class__.__name__), errors) return result
def __call__(self, value): value, errors = self.schema.loads(value) if isinstance( value, str) else self.schema.load(value) if errors: raise InvalidTypeData( 'Invalid {0} passed in'.format(self.schema.__class__.__name__), errors) return value
def __call__(self, value): # In marshmallow 2 schemas return tuple (`data`, `errors`) upon loading. They might also raise on invalid data # if configured so, but will still return a tuple. # In marshmallow 3 schemas always raise Validation error on load if input data is invalid and a single # value `data` is returned. if MARSHMALLOW_MAJOR_VERSION is None or MARSHMALLOW_MAJOR_VERSION == 2: value, errors = self.schema.dump(value) else: errors = {} try: value = self.schema.dump(value) except ValidationError as e: errors = e.messages if errors: raise InvalidTypeData('Invalid {0} passed in'.format(self.schema.__class__.__name__), errors) return value