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.UnmarshalMap casts empty Lists to nil #1890

Closed
jcoyne opened this issue Apr 11, 2018 · 2 comments · Fixed by #2858
Closed

dynamodbattribute.UnmarshalMap casts empty Lists to nil #1890

jcoyne opened this issue Apr 11, 2018 · 2 comments · Fixed by #2858
Labels
duplicate This issue is a duplicate. feature-request A feature should be added or improved.

Comments

@jcoyne
Copy link
Contributor

jcoyne commented Apr 11, 2018

Please fill out the sections below to help us address your issue.

Version of AWS SDK for Go?

v1.13.16

Version of Go (go version)?

1.9.3

What issue did you see?

When I have a record with an empty list in dynamodb, and I read it with the go sdk, and call dynamodbattribute.UnmarshalMap, then empty list values are cast to nil.

Steps to reproduce

Create an record with an empty list on the CLI:

aws dynamodb put-item --table-name resources \
--item '{"id": { "S": "555" }, "foo": { "L": [] }}'

Then fetch the record and unmarshal it:

        params := &dynamodb.GetItemInput{
		Key: map[string]*dynamodb.AttributeValue{
			"id": {
				S: aws.String(id),
			},
		},
		TableName:     aws.String(myTableName),
		ConsistentRead: aws.Bool(true),
	}
	resp, err := svc.GetItem(params)
        ...
        var json map[string]interface{}
	if err := dynamodbattribute.UnmarshalMap(resp.Item, &json); err != nil {
		panic(err)
	}
        log.Printf("JSON: %s", json)

The output is:

Item: map[id:555 foo:<nil>]

But I would expect:

Item: map[id:555 foo:[]]

If you have have an runnable example, please include it.

@jasdel
Copy link
Contributor

jasdel commented Apr 18, 2018

Thanks for reporting this issue @jcoyne. I think this is a duplicate of the outstanding feature request #682. Generally empty lists are invalid DynamoDB attribute values. This is why the SDK uses NULL. Though #682 highlights this is not always the the case. +1'ing that feature request will help us prioritize it in the SDK's backlog.

@jasdel jasdel added duplicate This issue is a duplicate. feature-request A feature should be added or improved. labels Apr 18, 2018
@skmcgrail
Copy link
Member

#2834 has been merged which implements a new (un)marshaler option for altering this behavior.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate This issue is a duplicate. feature-request A feature should be added or improved.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants