jpmckinney / validictory

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

invokation order of validators causes problems #4

Closed quodt closed 13 years ago

quodt commented 13 years ago

I've problems while validating one field in my schema with a custom format validator.

hier ist a snippet of my schema containing the field i like to validate:

    "periods": {"type": "array",
                "description": "Contract periods",
                "required": True,
                "items": contract_period,
                "format": "sl:contract-periods",
                "minItems": 1}

I've registered a custom formatter called 'sl:contract-periods' which does some checks with the contained items in the field. Since the method __validate() loops thru all schema properties to determine the required validators the validator called validate_format will get invoked earlier than the method validate_minItems , validate_optional or validate_type_array. So in my custom validator i have to check if the value is not None, a list-type and not empty which should get checked by the particular validators.

One possible solution could be to hardcode a list of validators to force a sorting order and appending the not hardcoded validators to the list for the loop. But there may be nicer ways...

jamesturk commented 13 years ago

just want to let you know I am looking at possible options, I think we can come up with a reasonable solution for this. had you put any thought into the proposed order?

quodt commented 13 years ago

at the very beginning i would check if optional, then i would check the type. after that i would validate things like minLength, maximum and things like that. finally i would check the format.

Checks like blank or pattern make only sense after the check for 'type'.

The checks for title and description are not critical so it doesn't matter when to check.

For checks like dependencies or additionalProperties i do not really have an opinion.

i know the list is not complet but these are just some thoughts since i did not read each check in detail.

jamesturk commented 13 years ago

Sorry about the delay it has been a hectic month.. I've pushed an ordering branch, can you check if that meets your needs and if so I'll merge it into master

quodt commented 13 years ago

i'm afraid my shout was not justified. if a validator just returns if it does not get a value it has to validate we do not have a problem. i guess this issue can be classified as "human failure" and could get closed. sorry for the noise.

jamesturk commented 13 years ago

ah alright, no problem