cerberus
cerberus copied to clipboard
Float validation passing when value is False
Use-case abstract
I have the following validation schema and value, both incoming as jsons from REST:
{
"premium": {"type": "float", "nullable": false, "empty": false}
}
"form_data": {"premium": false}
I'm guessing it's because float(False) is evaluated to 0.0. Sorry in advance if its something i haven't read carefully in the docs. In here it says it should work correctly: https://docs.python-cerberus.org/en/stable/validation-rules.html?highlight=float#type
the docs are missing the fact that integers (and thus booleans) are also considered to be of float
type. that behaviour was added five years ago, see a97293498581faf362ea9ba2f3b3a1be5f7c297d
my advise would be that you use the number
type, define a custom type or override the default TypeDefinition
.
the current type system is inconsitent, in #374 i propose a more consistent set of type definitions. it would also fail your expectations, so you might give feedback there.
this can be closed (fixed by #374, bf67dd9d)