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

attributevalue.MarshalMap() to AttributeValueMemberNULL field with double pointer #2726

Open
2 tasks done
kmacmcfarlane opened this issue Jul 25, 2024 · 1 comment
Open
2 tasks done
Assignees
Labels
bug This issue is a bug. feature/dynamodb/attributevalue Pertains to dynamodb attributevalue marshaler HLL (feature/dynamodb/attributevalue). p3 This is a minor priority issue queued This issues is on the AWS team's backlog

Comments

@kmacmcfarlane
Copy link

kmacmcfarlane commented Jul 25, 2024

Acknowledgements

Describe the bug

When working with dynamodb using attributevalue.MarshalMap() on a struct with omitempty on a field, I want to be able to return a types.AttributeValueMemberNULL in order to null out a field in dynamodb.

To achieve this, I want to use a double pointer on the field such that I can assign a nil pointer to my primative type and reference it with the double pointer. When encoding to JSON, for instance, this will encode the value null for that field in the output. The MarshalMap() appears to mistakenly think that the value double pointed to is nil, that it should not output anything when omitempty is set on the struct.

Expected Behavior

I would expect types.AttributeValueMemberNULL to be returned for the key in the result av map.

Current Behavior

The key for the struct field is omited from the map.

Reproduction Steps

package store

import (
	"github.com/aws/aws-sdk-go-v2/feature/dynamodb/attributevalue"
	"github.com/aws/aws-sdk-go-v2/service/dynamodb/types"
	. "github.com/onsi/ginkgo/v2"
	. "github.com/onsi/gomega"
)

var _ = Describe("recreate", func() {

	It("set Foo to attributevalue NULL", func() {

		// given
		var nilVal *int
		s := struct {
			Foo **int `dynamodbav:"foo,omitempty"`
		}{
			Foo: &nilVal,
		}

		av, err := attributevalue.MarshalMap(s)
		Expect(err).ShouldNot(HaveOccurred())
		Expect(av["foo"]).Should(BeAssignableToTypeOf(types.AttributeValueMemberNULL{}))
	})
})

Possible Solution

Check if a value of a pointer is a non-nil pointer to another pointer that is nil, in that case, return a types.AttributeValueMemberNULL instead of omitting the field from the output.

Additional Information/Context

No response

AWS Go SDK V2 Module Versions Used

github.com/aws/aws-sdk-go-v2 v1.30.3
github.com/aws/aws-sdk-go-v2/feature/dynamodb/attributevalue v1.14.10
github.com/aws/aws-sdk-go-v2/feature/dynamodb/expression v1.7.32
github.com/aws/aws-sdk-go-v2/service/dynamodb v1.34.4

Compiler and Version used

go version go1.22.2 linux/amd64

Operating System and version

Fedora 39

@kmacmcfarlane kmacmcfarlane added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Jul 25, 2024
@RanVaknin RanVaknin self-assigned this Jul 25, 2024
@kmacmcfarlane kmacmcfarlane changed the title (short issue description) attributevalue.MarshalMap() to AttributeValueMemberNULL field with double pointer Jul 26, 2024
@kmacmcfarlane
Copy link
Author

Digging deeper, what I am looking for with a double pointer is a combination of omitempty and nullempty behaviors. If the outer pointer is nil I want the field omitted from the output, and if only the inner pointer is nil, I want a null attributevalue to be encoded.

@RanVaknin RanVaknin added p3 This is a minor priority issue feature/dynamodb/attributevalue Pertains to dynamodb attributevalue marshaler HLL (feature/dynamodb/attributevalue). queued This issues is on the AWS team's backlog and removed needs-triage This issue or PR still needs to be triaged. labels Jul 30, 2024
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. feature/dynamodb/attributevalue Pertains to dynamodb attributevalue marshaler HLL (feature/dynamodb/attributevalue). p3 This is a minor priority issue queued This issues is on the AWS team's backlog
Projects
None yet
Development

No branches or pull requests

2 participants