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

Instance validates if multipleOf is an integer, but fails if it's a float #1159

Open
Zac-HD opened this issue Sep 10, 2023 · 3 comments
Open
Labels
Bug Something doesn't work the way it should.

Comments

@Zac-HD
Copy link
Member

Zac-HD commented Sep 10, 2023

from jsonschema import validate

instance = 9007199254740995
validate(instance, schema={"type": "integer", "multipleOf": 11})    # passes
validate(instance, schema={"type": "integer", "multipleOf": 11.0})  # fails

I'm pretty sure that this is a bug, on the basis that the spec says all integer-valued numbers should be treated as integers.

Found via python-jsonschema/hypothesis-jsonschema#103.

@Julian
Copy link
Member

Julian commented Sep 10, 2023

Nice :)

Needs thinking though / reading the spec language. It's true the spec says to treat floats with no fractional part as integers, but it also says (or really leaves the JSON spec to say) that floats are an acceptable implementation of number -- and I'm not sure where if anywhere covers what the requirements are on coercion to a common type.

Specifically here, 9007199254740995 is not representable as a float, the closest float is 9007199254740996.0 which is indeed not divisible by 11, so doing the division somehow will require coercing to float.

But it's possible you're both correct on whether this is covered by the spec and also possible this is fixable, not sure, needs thinking.

@Zac-HD
Copy link
Member Author

Zac-HD commented Sep 10, 2023

Both passed on older versions of jsonschema, so for whatever it's worth this probably changed in version 4.18. I've just skipped the affected test though, and happy to go with your opinion 👍

@Julian
Copy link
Member

Julian commented Sep 10, 2023 via email

@Julian Julian added the Bug Something doesn't work the way it should. label Oct 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something doesn't work the way it should.
Projects
None yet
Development

No branches or pull requests

2 participants