23andMe / Yamale

A schema and validator for YAML.
MIT License
670 stars 88 forks source link

4.0.0 regression: int(min=-1) does not work anymore without quotes around '-1' #176

Closed grusin closed 2 years ago

grusin commented 2 years ago

there is a regression in 4.0.0 that was released today. int(min=-1) does not work anymore, it has to be int(min='-1') to work.

on 3.0.7 version it used to work.

example of not working code anymore:

import yamale

schema = yamale.make_schema(content="""
max_defect_perc: int(required=True, min=0, max=100)
max_defect_row_count: int(min=-1)
""")

data = yamale.make_data(content='''
max_defect_perc: 100
max_defect_row_count: -1
''')

yamale.validate(data=data, schema=schema)

example of working code:

import yamale

schema = yamale.make_schema(content="""
max_defect_perc: int(required=True, min=0, max=100)
max_defect_row_count: int(min='-1')
""")

data = yamale.make_data(content='''
max_defect_perc: 100
max_defect_row_count: -1
''')

yamale.validate(data=data, schema=schema)
mildebrandt commented 2 years ago

Thank you! I'm surprised this isn't in our test cases. We're taking a look.

litghost commented 2 years ago

This also affected num(min=-1), unclear if the fix works there too, but I don't see a num test with a negative bound.

mildebrandt commented 2 years ago

@litghost Thanks for checking! The constraints within the validators are shared, so the new test will cover it. In this case, both int() and num() use the Min constraint found here: https://github.com/23andMe/Yamale/blob/master/yamale/validators/constraints.py#L60-L71

Please let us know if you have any other questions. Thanks!

grusin commented 2 years ago

thanks for fast reaction :)