Closed
Description
Acknowledgements
- I have searched (https://github.com/aws/aws-sdk/issues?q=is%3Aissue) for past instances of this issue
- I have verified all of my SDK modules are up-to-date (you can perform a bulk update with
go get -u github.com/aws/aws-sdk-go-v2/...
)
Describe the bug
When unmarshaling StringSet or NumberSet values via attributevalue.Unmarshal
, unmarshaller interface receives the whole set instead of individual slice items.
Unmarshaler is called here: https://github.com/aws/aws-sdk-go-v2/blob/main/feature/dynamodb/attributevalue/decode.go#L807
for i := 0; i < v.Cap() && i < len(ss); i++ {
if !isArray {
v.SetLen(i + 1)
}
u, elem := indirect[Unmarshaler](v.Index(i), indirectOptions{})
if u != nil {
// This should pass `&types.AttributeValueMemberS{Value: s[i]}`
return u.UnmarshalDynamoDBAttributeValue(&types.AttributeValueMemberSS{Value: ss})
}
if err := d.decodeString(ss[i], elem, tag{}); err != nil {
return err
}
}
This issue is present in both dynamodb/attributevalue
and dynamodbstreams/attributevalue
Regression Issue
- Select this option if this issue appears to be a regression.
Expected Behavior
Unmarshaler should receive individual set items
Current Behavior
Unmarshaler receives the whole set
Reproduction Steps
package main
import (
"errors"
"github.com/aws/aws-sdk-go-v2/feature/dynamodb/attributevalue"
"github.com/aws/aws-sdk-go-v2/service/dynamodb/types"
)
type myType string
type doc struct {
Items []myType `dynamodbav:"items,stringset"`
}
func (m *myType) UnmarshalDynamoDBAttributeValue(av types.AttributeValue) error {
switch v := av.(type) {
case *types.AttributeValueMemberS:
*m = myType(v.Value)
return nil
default:
return errors.New("unexpected type")
}
}
func main() {
d := doc{
Items: []myType{"a", "b"},
}
av, err := attributevalue.Marshal(d)
if err != nil {
panic(err)
}
var d2 doc
if err := attributevalue.Unmarshal(av, &d2); err != nil {
panic(err)
}
}
Possible Solution
- return u.UnmarshalDynamoDBAttributeValue(&types.AttributeValueMemberSS{Value: ss})
+ return u.UnmarshalDynamoDBAttributeValue(&types.AttributeValueMemberS{Value: ss[i]})
Additional Information/Context
No response
AWS Go SDK V2 Module Versions Used
github.com/aws/aws-sdk-go-v2 v1.27.1
github.com/aws/aws-sdk-go-v2/feature/dynamodb/attributevalue v1.14.0
github.com/aws/aws-sdk-go-v2/feature/dynamodb/expression v1.7.22
github.com/aws/aws-sdk-go-v2/service/dynamodb v1.32.7
Compiler and Version used
go version go1.23.2 darwin/arm64
Operating System and version
MacOS