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

dynamodbattribute panics unmarshaling number into string typedef #3983

Closed
3 tasks done
rittneje opened this issue Jun 30, 2021 · 5 comments · Fixed by #4068 or #4105
Closed
3 tasks done

dynamodbattribute panics unmarshaling number into string typedef #3983

rittneje opened this issue Jun 30, 2021 · 5 comments · Fixed by #4068 or #4105
Labels
bug This issue is a bug. investigating This issue is being investigated and/or work is in progress to resolve the issue.

Comments

@rittneje
Copy link
Contributor

rittneje commented Jun 30, 2021

Confirm by changing [ ] to [x] below to ensure that it's a bug:

Describe the bug

Unmarshaling an AttributeValue number into a string typedef panics.

case reflect.String:
if v.Type() == numberType { // Support Number value type
v.Set(reflect.ValueOf(Number(*n)))
return nil
}
v.Set(reflect.ValueOf(*n))

This should use v.SetString(*n) instead of v.Set(reflect.ValueOf(*n))

Version of AWS SDK for Go?

v1.38.65

Version of Go (go version)?

1.15.13

To Reproduce (observed behavior)

package main

import (
	"fmt"
	"log"

	"github.com/aws/aws-sdk-go/aws"
	"github.com/aws/aws-sdk-go/service/dynamodb"
	"github.com/aws/aws-sdk-go/service/dynamodb/dynamodbattribute"
)

type Foo string

type Bar struct {
	F Foo
}

func main() {
	m := map[string]*dynamodb.AttributeValue{
		"F": &dynamodb.AttributeValue{
			N: aws.String("12345"),
		},
	}

	var b Bar

        // This line panics.
	err := dynamodbattribute.UnmarshalMap(m, &b)
	if err != nil {
		log.Println(err)
	} else {
		fmt.Println(b)
	}
}

This yields "panic: reflect.Set: value of type string is not assignable to type main.Foo"

For reference: https://play.golang.org/p/uTdKemtyvLv

@rittneje rittneje added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Jun 30, 2021
@rittneje
Copy link
Contributor Author

ping @jasdel

@rittneje
Copy link
Contributor Author

@jasdel @KaibaLopez Are there plans to fix this?

@rittneje
Copy link
Contributor Author

@jasdel @KaibaLopez This bug was filed almost two months ago.

@jasdel
Copy link
Contributor

jasdel commented Aug 20, 2021

Thanks for reaching out @rittneje and reporting this issue. I've been able to reproduce this issue. It looks like the issue that is causing Set not to work is the string alias being used. The Unmarshaler should be able to handle aliased types. SetString would fix this, and it looks like this pattern is used for the other basic types.

Will investigate if there are other cases this is happening.

@jasdel jasdel added investigating This issue is being investigated and/or work is in progress to resolve the issue. and removed needs-triage This issue or PR still needs to be triaged. labels Aug 20, 2021
jasdel added a commit to jasdel/aws-sdk-go that referenced this issue Aug 20, 2021
Fixes aws#3983 by correcting the unmarshaler's decoding of AttributeValue N
parameter into string aliased type.
jasdel added a commit that referenced this issue Sep 20, 2021
Fixes #3983 by correcting the unmarshaler's decoding of AttributeValue N
parameter into string aliased type.
@github-actions
Copy link

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

aws-sdk-go-automation pushed a commit that referenced this issue Sep 21, 2021
===

### Service Client Updates
* `service/comprehend`: Updates service API, documentation, and paginators
* `service/ec2`: Updates service API, documentation, and paginators
  * This update adds support for downloading configuration templates using new APIs (GetVpnConnectionDeviceTypes and GetVpnConnectionDeviceSampleConfiguration) and Internet Key Exchange version 2 (IKEv2) parameters for many popular CGW devices.
* `service/ecr`: Updates service API and documentation
  * This release adds additional support for repository replication
* `service/iot`: Updates service API and documentation
  * This release adds support for verifying, viewing and filtering AWS IoT Device Defender detect violations with four verification states.
* `service/kafka`: Updates service API

### SDK Bugs
* `service/dynamodb/dynamodbattribute`: Fix string alias unmarshal.
  * Fixes #3983 by correcting the unmarshaler's decoding of AttributeValue number (N) parameter into type that is a string alias.
aws-sdk-go-automation added a commit that referenced this issue Sep 21, 2021
Release v1.40.46 (2021-09-21)
===

### Service Client Updates
* `service/comprehend`: Updates service API, documentation, and paginators
* `service/ec2`: Updates service API, documentation, and paginators
  * This update adds support for downloading configuration templates using new APIs (GetVpnConnectionDeviceTypes and GetVpnConnectionDeviceSampleConfiguration) and Internet Key Exchange version 2 (IKEv2) parameters for many popular CGW devices.
* `service/ecr`: Updates service API and documentation
  * This release adds additional support for repository replication
* `service/iot`: Updates service API and documentation
  * This release adds support for verifying, viewing and filtering AWS IoT Device Defender detect violations with four verification states.
* `service/kafka`: Updates service API

### SDK Bugs
* `service/dynamodb/dynamodbattribute`: Fix string alias unmarshal.
  * Fixes #3983 by correcting the unmarshaler's decoding of AttributeValue number (N) parameter into type that is a string alias.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue is a bug. investigating This issue is being investigated and/or work is in progress to resolve the issue.
Projects
None yet
2 participants