-
Notifications
You must be signed in to change notification settings - Fork 107
fix!: don't unwrap int, double by default, add a warning when a number is autoconverted to double or int #773
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
Changes from 3 commits
28c2327
8a5aba8
068b0bf
a7152f5
b125553
2d31c03
5b62746
39e618c
573880d
a2ba674
beab398
aa86a2f
1d80aea
b2f4e4d
3c6eb03
62f4f3e
2085357
b28df5f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,7 @@ import {PathType} from '.'; | |
import {protobuf as Protobuf} from 'google-gax'; | ||
import * as path from 'path'; | ||
import {google} from '../protos/protos'; | ||
import {type} from 'os'; | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-namespace | ||
export namespace entity { | ||
|
@@ -580,23 +581,6 @@ export namespace entity { | |
return valueProto; | ||
} | ||
|
||
if (typeof value === 'number') { | ||
if (Number.isInteger(value)) { | ||
if (!Number.isSafeInteger(value)) { | ||
process.emitWarning( | ||
'IntegerOutOfBoundsWarning: ' + | ||
"the value for '" + | ||
property + | ||
"' property is outside of bounds of a JavaScript Number.\n" + | ||
"Use 'Datastore.int(<integer_value_as_string>)' to preserve accuracy during the upload." | ||
); | ||
} | ||
value = new entity.Int(value); | ||
} else { | ||
value = new entity.Double(value); | ||
} | ||
} | ||
|
||
if (isDsInt(value)) { | ||
valueProto.integerValue = value.value; | ||
return valueProto; | ||
|
@@ -607,6 +591,38 @@ export namespace entity { | |
return valueProto; | ||
} | ||
|
||
if (typeof value === 'number') { | ||
const integerOutOfBoundsWarning = | ||
crwilcox marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"'IntegerOutOfBoundsWarning: the value for '" + | ||
property + | ||
"' property is outside of bounds of a JavaScript Number.\n" + | ||
"Use 'Datastore.int(<integer_value_as_string>)' to preserve accuracy during the upload."; | ||
|
||
const typeCastWarning = | ||
"TypeCastWarning: the value for '" + | ||
property + | ||
"' property is a JavaScript Number.\n" + | ||
"Use 'Datastore.int(<integer_value_as_string>)' or " + | ||
"'Datastore.double(<double_value_as_string>)' to preserve consistent " + | ||
'Datastore types during the upload.'; | ||
crwilcox marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
if (Number.isInteger(value)) { | ||
if (!Number.isSafeInteger(value)) { | ||
process.emitWarning(integerOutOfBoundsWarning); | ||
} else { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need the else here ? Also maybe move There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. They are exclusive. They both recommend the same outcome, but I think having two separate warnings is a bit confusing. This one warning is it could be dangerous, the other is destructive. I had what you recommended earlier but it is very very noisy :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note: added 'debouncing' you will only get a single typecast warning for the entity. that way it doesn't flood the warning feed. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It might be reasonable to augment the out of bounds warning to mention the type issue as well, since that'll still be an issue if they fix their number size issue. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since we're debouncing the typescast warning any ways, I'd consider just dropping the if and printing both. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think printing both could get noisy as Chris said. I ended up going with @feywind's suggestion here. |
||
process.emitWarning(typeCastWarning); | ||
} | ||
value = new entity.Int(value); | ||
valueProto.integerValue = value.value; | ||
return valueProto; | ||
} else { | ||
process.emitWarning(typeCastWarning); | ||
crwilcox marked this conversation as resolved.
Show resolved
Hide resolved
|
||
value = new entity.Double(value); | ||
valueProto.doubleValue = value.value; | ||
return valueProto; | ||
} | ||
} | ||
|
||
if (isDsGeoPoint(value)) { | ||
valueProto.geoPointValue = value.value; | ||
return valueProto; | ||
|
Uh oh!
There was an error while loading. Please reload this page.