-
Notifications
You must be signed in to change notification settings - Fork 92
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
type: 'any' in a remote method can coerce mongodb object ids into floats #299
Comments
Hey @vkarpov15, those types are LoopBack Types; 'any' is not a type according to the documentation... And now I see that we test for @vkarpov15, there are several issue with coercion that are currently being "cleaned up" by @bajtos , I will make sure that we consider this as well! Cheers |
@bajtos, I keep adding the "coercion clean up" to related bugs. If you have a different workflow in mind please let me know. I'm not sure if your fixes will cover all cases, but at the very least I think we should add documentation for any remaining coercion behavior as a part of the milestone. |
Yes, I can add that. Is the "Any" type name capitalized, as most of the other LoopBack types are? Will it match just any primitive type, or will it also match Object, Array, and GeoPoint types? |
It was lower case 'any' unfortunately - I assume the person that wrote it in the first place was anxious about whether the parameter would be a string or a full fledged mongodb ObjectId. |
It's I am pondering an idea of always encoding the id property as strings, see strongloop/loopback#2046 |
OK, I added it to the table in https://docs.strongloop.com/display/LB/LoopBack+types (and reordered the table alphabetically). One final question: Will |
IMO if you say "any" that should mean "no type coercion please, let me deal with it" |
This issue was fixed by #343 in LoopBack 3.0 (alpha). Model properties of "any" type sent in JSON request body are no longer converted from string to number. When the "any"-typed value comes from a string-only source like query-string, we convert to numbers only values that are "safe" to convert, meaning they we won't loose information as a result of the conversion. Most notably, integer values starting with |
Don't rush to release on our account, we've been loopback-free for a few months now and it's been a dream come true :) |
That's sad news. If I may ask you, what tool/framework/approach are you using now? |
If anyone faces the same issue - here is a boot script that fixes the problem for all methods:
|
If you have a remote method with a parameter that's
type: 'any'
, coerce can convert a mongodb object id into a float because mongodb object id hex strings can happen to be all numbers. Easily fixed on my end (usetype: 'string'
) but this is an annoying rough edge in the API IMO.The text was updated successfully, but these errors were encountered: