Skip to content

DynamoDB attribute names are incorrectly treated as case insensitive #2526

Closed
@adventureisyou

Description

Describe the bug

The dynamodb documentation specifically says that attribute names are case sensitive: https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/HowItWorks.NamingRulesDataTypes.html

However, in field_cache.go the field names are being "EqualFolded" which is essentially treating them as case-insensitive.

This results in failures to parse if the field types don't match, or worse, silent decoding of data into the wrong field if the types do match.

Expected Behavior

I expected the library to conform to the dynamo spec by treating attribute names as case-sensitive.

Current Behavior

The library treats attribute names as case insensitive.

Reproduction Steps

  1. Create a struct with dynamodbav tags on two fields with names that differ only by case. e.g:
type Example struct {
    Something string `dynamodbav:"a"`
    SomethingElse string `dynamodbav:"A"`
}
  1. Write an item to the table via this struct with the fields populated with different values.
  2. Read the item back from the table into the struct and observe that there is a chance (depending on order of processing) that the item was incorrectly parsed into the wrong fields.

Possible Solution

Commenting out the strings.EqualFold codepath seems to fix everything for me. Obviously that is a breaking change for anyone relying on this behaviour (though it's very shaky ground to rely on it).

AWS Go SDK V2 Module Versions Used

aws-sdk-go-v2/feature/dynamodb/[email protected]

Compiler and Version used

go version go1.21.4 darwin/arm64

Operating System and version

MacOS Sonoma 14.1.1

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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