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

Fixed DynamoDbEnhancedClient TableSchema::itemToMap to handle flatten… #5832

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

iulianbudau
Copy link
Contributor

@iulianbudau iulianbudau commented Jan 28, 2025

Fixed [DynamoDbEnhancedClient] TableSchema::itemToMap doesn't respect ignoreNulls with null @DynamoDbFlattened members #2540.

Description

Current behavior: TableSchema.fromBean(Bean.class).itemToMap(bean, false) returns a map without members of any @DynamoDbFlatten'd members if the flattened member is null even though ignoreNulls is set to false.

Expected behavior: TableSchema::itemToMap should return a map that contains a consistent representation of null top-level (non-flattened) attributes and flattened attributes when their "parent" member is null and ignoreNulls is set to false.

Motivation and Context

#2540

Modifications

Updated the StaticImmutableTableSchema -> Map<String, AttributeValue> itemToMap(T item, boolean ignoreNulls) logic to properly account for the ignoreNulls check and generate AttributeValue.fromNul(true) values for attributes of @DynamoDbFlattened members that are null.

Testing

Unit tests coverage added.

Screenshots (if appropriate)

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)

Checklist

  • I have read the CONTRIBUTING document
  • Local run of mvn install succeeds
  • My code follows the code style of this project
  • My change requires a change to the Javadoc documentation
  • I have updated the Javadoc documentation accordingly
  • I have added tests to cover my changes
  • All new and existing tests passed
  • I have added a changelog entry. Adding a new entry must be accomplished by running the scripts/new-change script and following the instructions. Commit the new file created by the script in .changes/next-release with your changes.
  • My change is to implement 1.11 parity feature and I have updated LaunchChangelog

License

  • I confirm that this pull request can be released under the Apache 2 license

@iulianbudau iulianbudau requested a review from a team as a code owner January 28, 2025 15:19
@joviegas
Copy link
Contributor

Please update the motivation with more details like why are we fixing this now ?
Was there issue reported or whats consequences of not fixing this ?

@iulianbudau iulianbudau reopened this Feb 19, 2025
@iulianbudau
Copy link
Contributor Author

iulianbudau commented Feb 19, 2025

Please update the motivation with more details like why are we fixing this now ? Was there issue reported or whats consequences of not fixing this ?

@joviegas Updated the PR with more details according to the template.

CHANGELOG.md Outdated
@@ -1,4 +1,9 @@
#### 👋 _Looking for changelogs for older versions? You can find them in the [changelogs](./changelogs) directory._
# __2.30.10__ __2025-01-30__
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove this change , since this are auto generated by release.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@@ -1386,6 +1386,11 @@ public void buildAbstractWithFlatten() {

assertThat(tableSchema.itemToMap(item, true),
is(singletonMap("documentString", AttributeValue.builder().s("test-string").build())));

Map<String, AttributeValue> attributeMapWithNulls = tableSchema.itemToMap(item, false);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add new test case for this with separate assertions ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New test added.

Map<String, AttributeValue> attributeMapWithNulls = tableSchema.itemToMap(item, false);
assertThat(attributeMapWithNulls.size(), is(2));
assertThat(attributeMapWithNulls, hasEntry("documentString", AttributeValue.builder().s("test-string").build()));
assertThat(attributeMapWithNulls, hasEntry("documentInteger", AttributeValue.fromNul(true)));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add a test case to check what happens when there is Inner Nested classe and self refering nested class

@DynamoDbBean
public class FlattenedImmutableBean {
    private String id;
    private String attribute1;
    @DynamoDbFlatten
    private AbstractImmutable abstractImmutable;

}


@DynamoDbImmutable(builder = AbstractImmutable.Builder.class)
public class AbstractImmutable {
    private final String attribute2;
    private final AbstractImmutable abstractImmutableOne;
}

We have some existing tests classes like src/test/java/software/amazon/awssdk/enhanced/dynamodb/mapper/testbeans/AbstractImmutable.java
can we add more cases here ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New tests added.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks 👍
Will run the codebuilds , and then approve and merge once code build passes

Map<String, AttributeValue> attributeMapWithNulls = tableSchema.itemToMap(item, false);
assertThat(attributeMapWithNulls.size(), is(2));
assertThat(attributeMapWithNulls, hasEntry("documentString", AttributeValue.builder().s("test-string").build()));
assertThat(attributeMapWithNulls, hasEntry("documentInteger", AttributeValue.fromNul(true)));
}
Copy link
Contributor

@joviegas joviegas Feb 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please add a test case for UpdateItem where we update DDB entry similar as #5380 , to make sure it works for nested classes

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@joviegas I checked the UpdateBehaviorTest class and it contains tests which covers updating DDB entry with nested and flatten members, with both IgnoreNullsMode.SCALAR_ONLY and IgnoreNullsMode.DEFAULT modes. Do you have specific scenario in mind which requires more coverage?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will have look at it today and update a sample test

Copy link
Contributor

@joviegas joviegas Feb 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeap I saw it now , then we are good.

@iulianbudau iulianbudau force-pushed the bugfix/table-schema-item-to-map-handle-null-flattened-members branch from d8b81f4 to e74034a Compare February 25, 2025 08:04
@iulianbudau iulianbudau force-pushed the bugfix/table-schema-item-to-map-handle-null-flattened-members branch from e74034a to 51eb1e8 Compare February 26, 2025 16:09
@joviegas joviegas enabled auto-merge February 28, 2025 04:29
@joviegas joviegas added this pull request to the merge queue Feb 28, 2025
github-merge-queue bot pushed a commit that referenced this pull request Feb 28, 2025
…ed members when ignoreNulls is false (#5832)

Co-authored-by: John Viegas <[email protected]>
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Feb 28, 2025
@joviegas joviegas added this pull request to the merge queue Feb 28, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Feb 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants