-
-
Notifications
You must be signed in to change notification settings - Fork 6.9k
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
IntegerField.to_internal_value coerces decimal to integer; should fail #2835
Comments
I'm afraid you'll need to customize the field if you want this behavior. While I absolutely understand see why you might want/expect this change, other folks probably wouldn't. |
It just seems inconsistent with Django, as entering floats in a Django form for IntegerField will raise a ValidationError, whereas in DRF 3.x it does not (I believe it did in DRF 2.x). Strangely enough, the expected ValidationError will be raised if the float is wrapped in a string (the attempt to coerce it to int fails "ValueError: invalid literal...") so it may even be inconsistent with itself. To clarify: This commit seems to return the field to the expected behavior: ryangallen@3e6a149 |
…s being stored as ints, fixes encode#2835. Match IntegerField validation with Django IntegerField, prevents decimal values being stored as ints, fixes encode#2835 On branch master
@tomchristie This pull handles cases where values such as 1.0 or "1.0" pass through as integers but values like 1.5 or "1.5" do not. It matches Django's IntegerField validation and I believe is the behavior most developers would expect. Changing a clear decimal value, say 0.4 to 0, is not expected and could have negative consequences in an application. |
only allow integer field to accept integers and strings, fixes #2835
The following items had a wrong href value: - Dont require pk strictly for related fields. (encode#2745, encode#2754) - Restrict integer field to integers and strings. (encode#2835, encode#2836)
The to_internal_value method coerces data to an int, so when a float/decimal is passed, the int value is saved, rather than raising an exception.
The text was updated successfully, but these errors were encountered: