Skip to content

DynamoDbTable.updateItem clears data from table, then only sets non-null field values #4711

Open
@ipsi-apant

Description

@ipsi-apant

Describe the bug

When executing DynamoDbTable.updateItem for a few fields, the execution clear the existing data and only sets new field values from input object.
My understanding, for an existing record, when a Java object populated with primary key and fields to be changed, this operation should affect only the fields to be changed for the primary key record.
Curious to know, how is this updateItem supposed to work?

Expected Behavior

  • The updateItem should only change the fields which are present in the input
  • This begs a question what should happen to the default values which are assigned as null. There is a field level annotation for ignoring null (I tried, it didn't work for me either). Also, need a class level annotation for ignoring all null fields.

Current Behavior

Overwriting existing contents of a record for updateItem operation.

I am using spring-cloud-aws-starter-dynamodb using DynamoDbTemplate AWS Spring DynamoDb, however, it fails when using below code snippet

/*
Existing record:
 Car(vin=1234567890, color=white, year=2020, model=Ford Mustang)
*/

final Car car = Car
    .builder()
    .vin("1234567890")
    .color("black") // existing record has white color
    .build();

Car updatedCar = dynamoDbEnhancedClient.table("Car", TableSchema.fromBean(Car.class))
                                    .updateItem(car);

assertEquals("black", updatedCar.getColor()); // PASS
assertEquals("2020", updatedCar.getYear()); // FAIL
assertEquals("Ford Mustang", updatedCar.getModel()); // FAIL

Reproduction Steps

  1. Create a Car table with fields vin (primary key), year, model, color
  2. Create Java class named as Car
  3. Add class level annotation @DynamoDbBean
  4. Add @DynamoDbPartitionKey annotation to a getter method of vin
  5. Add a new record in Car table as mentioned in Current Behavior
  6. Create an instance of dynamoDbEnhancedClient
  7. Execute code snippet as mentioned in Current Behavior

Possible Solution

  • updateItem should only affect the values in the input
  • This begs a question what should happen to the default values which are assigned as null. There is a field level annotation for ignoring null (it didn't work for me either). Also, need a class level annotation for ignoring all null fields.

Additional Information/Context

  • Springboot 3.1.5
  • Java 21
  • AWS SDK 2.20.153
  • spring-cloud-aws-starter-dynamodb 3.0.2

AWS Java SDK version used

2.20.153

JDK version used

21

Operating System and version

Windows 11 Pro x64

Metadata

Metadata

Assignees

Labels

bugThis issue is a bug.dynamodb-enhancedp3This is a minor priority issue

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions