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

Add support for omitting attribute values returned by custom Marshaler implementations #1429

Closed
lmika opened this issue Sep 20, 2021 · 2 comments
Assignees
Labels
feature-request A feature should be added or improved. l Effort estimation: large p3 This is a minor priority issue queued This issues is on the AWS team's backlog

Comments

@lmika
Copy link

lmika commented Sep 20, 2021

Is your feature request related to a problem? Please describe.

We are working on a project that uses a custom type to represent UUIDs. This type, which extends github.com/google/uuid, stores the UUID in memory as a [16]byte array, but we’ve added a custom Marshal and Unmarshal implementation that marshals/unmarshals it to a string UUID representation.

We were hoping to allow the service writing rows to the DynamoDB table to omit an id field when the UUID is nil (i.e. 16 zero bytes). However, we’ve discovered that this is not possible to do when using a type that implements
github.com/aws/aws-sdk-go-v2/service/dynamodb/dynamodbattribute.Marshaler. We’re hoping that this could be added in some way.

Describe the solution you'd like

There’s not a huge preference as to how this is implemented, either the following suggestion or one of the alternatives will be find. Depending on the stability of the API, an ideal solution would be to return double nil from Marshal.MarshalDynamoDBAttributeValue to indicate that no attribute value should be marshalled out. Example:

func (u UUID) MarshalDynamoDBAttributeValue() (types.AttributeValue, error) {
	if u == NilUUID {
		// Indicate that no value should be stored for this attribute.
		return nil, nil
	}

	return &types.AttributeValueMemberS{
		Value: u.String(),
	}, nil
}

Describe alternatives you've considered

A few other suggestions for this approach:

  • Add support for omitempty in the struct tag for custom types. So using the example above, if u is NilUUID, then the function will return a types.AttributeValueMemberS with an empty string. Since the field that has this type also has the omitempty option in the struct tag, the value won’t be marshalled out to the database.
  • Either a dedicated attribute type or error type that acts as a sentinal would also work.

Additional context

We’re using “aws-sdk-go-v2” version 1.5.0 with Go 1.16.6

@lmika lmika added feature-request A feature should be added or improved. needs-triage This issue or PR still needs to be triaged. labels Sep 20, 2021
@KaibaLopez KaibaLopez 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 Dec 17, 2021
@jasdel jasdel added needs-triage This issue or PR still needs to be triaged. and removed investigating This issue is being investigated and/or work is in progress to resolve the issue. labels Sep 2, 2022
@RanVaknin RanVaknin self-assigned this Nov 7, 2022
@RanVaknin RanVaknin added p3 This is a minor priority issue l Effort estimation: large labels Nov 7, 2022
@RanVaknin RanVaknin removed the needs-triage This issue or PR still needs to be triaged. label Mar 27, 2023
@RanVaknin RanVaknin added the queued This issues is on the AWS team's backlog label Feb 22, 2024
@lucix-aws
Copy link
Contributor

I think this is addressed in #2739?

Copy link

This issue is now closed. Comments on closed issues are hard for our team to see.
If you need more assistance, please open a new issue that references this one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request A feature should be added or improved. l Effort estimation: large 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

5 participants