cerberus icon indicating copy to clipboard operation
cerberus copied to clipboard

Float validation passing when value is False

Open shsimeonova opened this issue 5 years ago • 2 comments

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

shsimeonova avatar Jun 04 '19 07:06 shsimeonova

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.

funkyfuture avatar Jun 04 '19 10:06 funkyfuture

this can be closed (fixed by #374, bf67dd9d)

nnrepos avatar Oct 05 '22 10:10 nnrepos