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

passing a float to colander.Integer does not throw exception #292

Closed
cecemel opened this issue Jul 3, 2017 · 2 comments
Closed

passing a float to colander.Integer does not throw exception #292

cecemel opened this issue Jul 3, 2017 · 2 comments

Comments

@cecemel
Copy link

cecemel commented Jul 3, 2017

When passing a float value (e.g. 1.21) to a colander.Integer node, no exception is thrown.
I am not sure of the expected behaviour though...

Version: 1.3.3

@digitalresistor
Copy link
Member

Internally the conversion is passed to int(), and Python parses the string and returns an integer: https://github.com/Pylons/colander/blob/master/colander/__init__.py#L1417

Floats will silently truncated.

Adding some extra protection wouldn't be entirely out of line IMHO.

@digitalresistor
Copy link
Member

@cecemel Use Integer(strict=True) for this to correctly raise an exception if passed a float instead of a real integers.

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