You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When converting DynamoDBAttributeValue using Integer() method it currently hides the conversion to Float64 one is passed.
This hidden functionality hides its true nature and has led to errors downstream.
We are doing this as we are having to convert from a DynamoDBAttributeValue to json and therefore could be a float or an int
Example:
package main
import (
"fmt""github.com/aws/aws-lambda-go/events"
)
funcmain() {
varvalinterface{}
varerrerror// We may receive a float64 or an integerattr:=events.NewNumberAttribute("0.123344")
val, err=attr.Integer()
iferr!=nil {
// expect an error here but Integer() will return int64(float64) truncating the decimal// amd hiding the error.// we are therefore not able to correctly cast to float64val, err=attr.Float()
}
// To JSON - We are using a map as we are not sure what the key/values will be from the dynamodb streamoutput:=map[string]interface{}{
"key": val,
}
b, err:=json.Marshal(output)
iferr!=nil {
panic(err)
}
fmt.Println(string(b))
// Output: {"key":0}
}
It would seem more predictable behaviour for Integer() to return an error if DynamoDBAttributeValue is not of integer type.
The text was updated successfully, but these errors were encountered:
The int64 returned by Integer() can't contain the largest DynamoDB Number either :) https://stackoverflow.com/a/53056505. If giant values or extreme precision matters, you may want to consider using String(), and the possibly the math/big library, to help fully preserve values downstream.
I'm also OK with an Int64(), that preserves the parse error, being added.
Uh oh!
There was an error while loading. Please reload this page.
When converting
DynamoDBAttributeValue
usingInteger()
method it currently hides the conversion toFloat64
one is passed.This hidden functionality hides its true nature and has led to errors downstream.
We are doing this as we are having to convert from a
DynamoDBAttributeValue
tojson
and therefore could be afloat
or anint
Example:
It would seem more predictable behaviour for
Integer()
to return an error ifDynamoDBAttributeValue
is not ofinteger
type.The text was updated successfully, but these errors were encountered: