-
-
Notifications
You must be signed in to change notification settings - Fork 929
(wip) Posting a number when property type is string doesn't trigger an error #774
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
Conversation
@@ -32,7 +33,7 @@ Feature: Create-Retrieve-Update-Delete | |||
"dummy": null, | |||
"dummyBoolean": null, | |||
"dummyDate": "2015-03-01T10:00:00+00:00", | |||
"dummyPrice": null, | |||
"dummyPrice": 1.2, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note here without quotes
@@ -62,7 +63,7 @@ Feature: Create-Retrieve-Update-Delete | |||
"dummy": null, | |||
"dummyBoolean": null, | |||
"dummyDate": "2015-03-01T10:00:00+00:00", | |||
"dummyPrice": null, | |||
"dummyPrice": "1.2", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There it returns a string
@@ -16,7 +16,8 @@ Feature: Create-Retrieve-Update-Delete | |||
"value1", | |||
"value2" | |||
] | |||
} | |||
}, | |||
"dummyPrice": 1.2 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should throw an error here because you pass a int and it wants a string. It's a bug.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1
Maybe ralted to symfony/symfony@62d28f9#diff-7a8fb8072d57f95ea6e37898b05895bc |
Yes so the only bug here is that we should send a string, but actually the number is accepted, so this test should fail. I'm leaving this open until I got time to fix it. |
05973e9
to
4580314
Compare
4580314
to
249eccc
Compare
"dummyFloat": null, | ||
"dummyPrice": null, | ||
"dummyFloat": 1.2, | ||
"dummyPrice": "1.2", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This fails and is a Number
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is no longer failing (see Travis build). So the bug is no longer present.
} | ||
}, | ||
"dummyFloat": 1.2, | ||
"dummyPrice": 1.2 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is accepted. What should be the consistent behavior here:
- Only allowing strings when type is
Decimal
? Allowing javascript numbers, but also serializingDecimal
types as numbers?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that I think the second solution would be cleaner, as that there are no difference between floats and decimals in json.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, decimal strings should always remain as strings even in JSON. Using float means possible loss of precision (the reason why we use decimal strings in the first place!)
So in other words, sending a floating-point value when the type is decimal is simply wrong. It is error-prone.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, forgot that the precision loss is also due to php... Would you be able to tell me where I may fix this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this still a problem?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The behaviour seems to be correct, since the test is failing (because dummyPrice cannot be float).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wtf, had not updated dependencies sorry for wasting your time...
See PR comment.
Can someone tell me how we know it's a number, even though the
@var
is typedstring
here?There might be a bug in the docs specifically with the@ORM(type=decimal)
opposed tofloat
(not proofed yet).