jpmckinney / validictory

🎓 deprecated general purpose python data validator
Other
240 stars 57 forks source link

SchemaError rising error immidiately even with fail_fast=False #97

Closed felixrojauro closed 7 years ago

felixrojauro commented 8 years ago

Hello, basically my use case is as follows: I want to vaildate that input json contains all required keys (values don't matter) and contains no unexpected keys. If given input contains unexpected key Schema error is thrown and exits immidiately. The reason for that lays here: raise SchemaError('Unknown properties for field "{fieldname}": {unknowns}'.format( fieldname=fieldname, unknowns=unknowns)) https://github.com/jamesturk/validictory/blob/master/validictory/validator.py#L199

this should check for fail_fast flag and either append error to list or rise error. like this maybe?

err = EasyAccessSchemaError('Unknown properties for field "{fieldname}": {unknowns}'.format(fieldname=fieldname, unknowns=unknowns), fieldname, delta) if self.fail_fast: raise err else: self._errors.append(err)

This makes it way easier to parse error output and return some useful data for the user

jamesturk commented 8 years ago

this is an interesting case, SchemaErrors are treated differently from validation errors right now since it is presumed the schema should always validate as it would typically be constant

I'd be glad to hear more about the use case for this and potentially make a change depending on how it'd affect other users. I'm a bit concerned about breaking compatibility though.

jamesturk commented 7 years ago

I've decided not to support this in light of #114