Skip to content

attributevalue behaves different from dynamodbattribute with omitemptyelem on maps #3117

Open
@curquhart

Description

@curquhart

Acknowledgements

Describe the bug

omitemptyelem does not omit empty maps from the dynamo attribute map. This differs from the sdk v1 functionality and can cause problems with constraints.

Regression Issue

  • Select this option if this issue appears to be a regression.

Expected Behavior

I would expect the map field (see sample code) to be omitted

Current Behavior

The map field (see sample code) is omitted by dynamodbattribute (sdk v1) but included by attributevalue (sdk v2)

Reproduction Steps

Sample code:

package main

import (
	"github.com/aws/aws-sdk-go-v2/feature/dynamodb/attributevalue"
	"github.com/aws/aws-sdk-go/service/dynamodb/dynamodbattribute"
)

type Record struct {
	M map[string]string `dynamodbav:"map,omitempty,omitemptyelem"`
}

func main() {
	mm1, err := dynamodbattribute.MarshalMap(&Record{
		M: make(map[string]string),
	})
	if err != nil {
		panic(err)
	}
	println("dynamodbattribute")
	for key := range mm1 {
		println(key)
	}

	mm2, err := attributevalue.MarshalMap(&Record{
		M: make(map[string]string),
	})
	if err != nil {
		panic(err)
	}
	println("attributevalue")
	for key := range mm2 {
		println(key)
	}
}

Output:

dynamodbattribute
attributevalue
map

Possible Solution

No response

Additional Information/Context

I don't know if this is actually an issue; I recognize this could be an intentional breaking change between SDK versions (since technically, an empty map is not a zero value), but I wanted to create this issue because even if it's not an issue, it could help identify it for other people migrating to the new SDK version.

AWS Go SDK V2 Module Versions Used

github.com/aws/aws-sdk-go v1.55.7
github.com/aws/aws-sdk-go-v2/feature/dynamodb/attributevalue v1.19.3
github.com/aws/aws-sdk-go-v2/service/dynamodb v1.43.4 // indirect
github.com/aws/aws-sdk-go-v2/service/dynamodbstreams v1.25.6 // indirect
github.com/aws/smithy-go v1.22.4 // indirect

Compiler and Version used

go version go1.24.0 darwin/arm64

Operating System and version

macos 15.5

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugThis issue is a bug.needs-triageThis issue or PR still needs to be triaged.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions