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

bugfix for auto generate UUID extension #5702

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

Conversation

Boyapati36
Copy link

@Boyapati36 Boyapati36 commented Nov 9, 2024

Fix: AutoGenerateUUIDExtension Overriding Existing Attribute Values

Motivation and Context

The AutoGenerateUUIDExtension was incorrectly overriding existing UUID values for items that already contained non-empty values. This change ensures that UUIDs are only generated if the specified attribute is missing or empty.

I believe that everybody wants to create a random UUID when they don't mention it and Updating the mentioned or given value didn't feel right.

This caused some major while I working on a project by using DynamoDbTable.updateItem() method. This method didn't update the existing record instead it saves a new record with auto-generated values. When I tag partition key with tag @DynamoDbAutoGeneratedUuid. I will never be able to update existing record in the Db using updateItem() method.

Fixes the issue where existing UUID attributes were being overwritten, which was not the intended behavior.

Modifications

  • Updated the insertUuidInItemToTransform method to check if the key exists and if its value is non-empty before generating a new UUID.
  • Added unit tests to validate the new behavior:
    • Test case 1: Ensures existing UUIDs are not overwritten.
    • Test case 2: Ensures that a new UUID is generated when the value is empty.

Testing

  • Ran unit tests in the local environment using mvn install.
  • Added new test cases to cover the modified logic:
    • Verified that the UUID is not overridden when already present.
    • Verified that new UUIDs are generated only when necessary.

Testing Environment:

  • Java 21
  • Spring Boot 3.x
  • DynamoDB local instance for integration tests

Screenshots (if appropriate)

N/A

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 does not require a change to the Javadoc documentation
  • 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

@@ -45,7 +45,7 @@ public class AutoGeneratedUuidExtensionTest {
private static final OperationContext PRIMARY_CONTEXT =
DefaultOperationContext.create(TABLE_NAME, TableMetadata.primaryIndexName());

private final AutoGeneratedUuidExtension atomicCounterExtension = AutoGeneratedUuidExtension.create();
private final AutoGeneratedUuidExtension autoGeneratedUuidExtension = AutoGeneratedUuidExtension.create();
Copy link
Author

Choose a reason for hiding this comment

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

Changed name of the extension object to be meaningful

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.

1 participant