Skip to content

multipleOf throwing ValidationError for specific number #1099

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

Closed
vigneshkv23 opened this issue May 15, 2023 · 1 comment
Closed

multipleOf throwing ValidationError for specific number #1099

vigneshkv23 opened this issue May 15, 2023 · 1 comment

Comments

@vigneshkv23
Copy link

vigneshkv23 commented May 15, 2023

This is a strange issue. I have created a simple JSON schema to validate float which can be a maximum of two digits.

schema = {'type': 'number', 'multipleOf': 0.01}
jsonschema.validate(1.11, schema)

=>jsonschema.validate(1.11, schema)
Traceback (most recent call last):
File "", line 1, in
File "C:\Python38\lib\site-packages\jsonschema\validators.py", line 934, in validate
raise error
jsonschema.exceptions.ValidationError: 1.11 is not a multiple of 0.01

Observations-

  1. From 1.11 till 1.19 throwing the validation error but from 1.21 No errors work as expected.
  2. Again from 10.11 till 10.21 throwing the validation error but from 10.22 No errors work as expected.
  3. 2.11 , 2.13 throwing the validation error
  4. But the other number works fine.
@Julian
Copy link
Member

Julian commented May 23, 2023

Hi there -- this is expected behavior, see e.g. some of the previous issues linked here.

Essentially, if you don't want float division, use decimal.Decimal when you deserialize your JSON.

@Julian Julian closed this as not planned Won't fix, can't repro, duplicate, stale May 23, 2023
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

2 participants