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

DynamoDBAttributeValue.String() accessor method inconsistent with documented behavior #510

Open
TylerHendrickson opened this issue Jun 29, 2023 · 0 comments

Comments

@TylerHendrickson
Copy link

TylerHendrickson commented Jun 29, 2023

Problem

The documented behavior for the DynamoDBAttributeValue.String() method, similar to the other accessor methods, states:

Method panics if the attribute is not of type String.

However, this does not appear to be the case.

Example

Using this code:

func IncorrectBehaviorExample() {
	input := []byte(`{"MyField": {"BOOL": true}}`)
	var item map[string]events.DynamoDBAttributeValue
	if err := json.Unmarshal(input, &item); err != nil {
		panic(err)
	}
	fmt.Println("Result:", item["MyField"].String())
}

does not panic, but outputs Result: {true 1}.

This is unlike the other accessor methods, such as .Number(), e.g.:

func CorrectBehaviorExample() {
	input := []byte(`{"MyField": {"BOOL": true}}`)
	var item map[string]events.DynamoDBAttributeValue
	if err := json.Unmarshal(input, &item); err != nil {
		panic(err)
	}
	fmt.Println("Result:", item["MyField"].Number())
}

which panics with panic: accessor called for incompatible type, requested type 5 but actual type was 1.

Suggestions

Either of:

  • Preferred: The method should panic if the attribute is not of type String, which is consistent with the documented behavior as well as the behavior of the other accessor methods.
  • Update the documentation so that it correctly reflects the behavior of the method.

Additional information

  • Observed when using github.com/aws/aws-lambda-go v1.41.0
  • Go 1.20
@TylerHendrickson TylerHendrickson changed the title DynamoDBAttributeValue accessor methods inconsistent with documented behavior DynamoDBAttributeValue.String() accessor method inconsistent with documented behavior Jul 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant