Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MultipleOf validation Bug #687

Closed
noelwilsondel opened this issue May 19, 2020 · 3 comments
Closed

MultipleOf validation Bug #687

noelwilsondel opened this issue May 19, 2020 · 3 comments

Comments

@noelwilsondel
Copy link

Hello,

Firstly thanks for this library it's really useful, we have noticed some unusual behaviour on version 3.2.0 validation using multipleOf constraint for example:

>>> from jsonschema import validate
>>> schema = {
...     "type" : "object",
...     "properties" : {
...         "test" : {"type" : "number", "multipleOf": 0.001},
...     },
... }
>>> # This should be valid but raises validation error
>>> validate(instance={"test" : 0.95}, schema=schema)

Some other things we noticed using the above value this passes:

>>> # This is valid
>>> validate(instance={"test" : 0.01}, schema=schema)
>>> # This is valid
>>> validate(instance={"test" : 0.1}, schema=schema)
>>> # This is invalid
>>> validate(instance={"test" : 0.95}, schema=schema)
@Julian
Copy link
Member

Julian commented May 19, 2020

Hi! Glad to hear.

Sorry you're having trouble -- this issue is just the way float division works -- have a look at some historical related issues.

If you don't want float division, use something with the precision you want, e.g. decimal.Decimal, when deserializing your JSON.

@Julian
Copy link
Member

Julian commented May 20, 2020

Hope that helps with some ideas, obviously happy to follow up.

@Julian Julian closed this as completed May 20, 2020
@jwnwilson
Copy link

@Julian We're attempting the parse_float=decimal.Decimal route thanks for the suggestion

Julian added a commit that referenced this issue Sep 20, 2023
4ecd01f30 Merge pull request #687 from swaeberle/check-single-label-idn-hostnames
732e7275a test single label IDN hostnames
ab3924a66 Merge pull request #685 from swaeberle/check-single-label-hostnames
9265a4fa9 do not test hostname with leading digit for older drafts
261b52db1 do not allow starting digits in hostnames for older drafts
9fc231ea4 test digits in hostnames
e9b20158e test plain single label hostnames
c8b57093d test valid single label hostnames
299aa7fe5 Merge pull request #682 from json-schema-org/useless-branch
fbb3cac60 Bump the sanity check to use a released version of jsonschema

git-subtree-dir: json
git-subtree-split: 4ecd01f30bce36a61224fa0f46c2c3f0cf7481dc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants