Skip to content

Conversation

soyuka
Copy link
Member

@soyuka soyuka commented Sep 28, 2016

Q A
Bug fix? not yet
New feature? no
BC breaks? no
Deprecations? no
Tests pass? should not
Fixed tickets #777
License MIT
Doc PR

See PR comment.

Can someone tell me how we know it's a number, even though the @var is typed string here?
There might be a bug in the docs specifically with the @ORM(type=decimal) opposed to float (not proofed yet).

@@ -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,
Copy link
Member Author

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",
Copy link
Member Author

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
Copy link
Member

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.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

@dunglas
Copy link
Member

dunglas commented Sep 29, 2016

@soyuka
Copy link
Member Author

soyuka commented Sep 29, 2016

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.

@soyuka soyuka changed the title Test dummyPrice behavior (wip) Test dummyPrice behavior Sep 29, 2016
@soyuka soyuka changed the title (wip) Test dummyPrice behavior (wip) Posting a number when property type is string doesn't trigger an error Sep 29, 2016
@teohhanhui teohhanhui added the bug label Sep 30, 2016
@soyuka soyuka mentioned this pull request Oct 6, 2016
@soyuka soyuka force-pushed the test-decimal-behavior branch from 05973e9 to 4580314 Compare October 6, 2016 09:36
@soyuka soyuka force-pushed the test-decimal-behavior branch from 4580314 to 249eccc Compare October 6, 2016 09:37
"dummyFloat": null,
"dummyPrice": null,
"dummyFloat": 1.2,
"dummyPrice": "1.2",
Copy link
Member Author

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.

Copy link
Contributor

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
Copy link
Member Author

@soyuka soyuka Oct 6, 2016

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 serializing Decimal types as numbers?

Copy link
Member Author

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.

Copy link
Contributor

@teohhanhui teohhanhui Oct 7, 2016

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.

Copy link
Member Author

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?

Copy link
Contributor

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?

Copy link
Contributor

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).

Copy link
Member Author

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...

@soyuka soyuka closed this Oct 7, 2016
@soyuka soyuka deleted the test-decimal-behavior branch October 7, 2016 09:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants