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

Change default behavior of Int and Double decoding to not convert to native javascript Number #774

Open
crwilcox opened this issue Dec 11, 2020 · 0 comments
Labels
api: datastore Issues related to the googleapis/nodejs-datastore API. type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.

Comments

@crwilcox
Copy link
Contributor

crwilcox commented Dec 11, 2020

Currently the entityFromEntityProto/decodeValueProto method, which is used to cast datastore entities into Javascript objects, converts DatastoreInt and DatastoreDouble to Number by default. While this was done to make the surface ergonomic for node programmers, there exists a case where a Double is indistinguishable from an int (3.0) in javascript. This results in a situation where a user changes a column type accidentally. Consider the following

Upload entity {description: 'a', rank: double("4.0")}
get entity
change description to 'b'
upload.
get.

The final get, due to auto unboxing, will be an int as on the retrieval 4.0 is seen to be the number 4, which is uploaded as an int.

I think we should support configuring wrapNumbers, but moving to default it to wrapping seems sensible.

Also, doubles should have the same option available.

related to #773

@product-auto-label product-auto-label bot added the api: datastore Issues related to the googleapis/nodejs-datastore API. label Dec 11, 2020
@crwilcox crwilcox added the type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design. label Dec 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: datastore Issues related to the googleapis/nodejs-datastore API. type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.
Projects
None yet
Development

No branches or pull requests

1 participant