Skip to content

[V4] Update DocumentModel to handle expressions without variables #3804

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

Open
wants to merge 1 commit into
base: development
Choose a base branch
from

Conversation

dscpinheiro
Copy link
Contributor

Fixes #3802

Motivation and Context

Fixes a regression introduced in V4 where an expression without variables would throw an AmazonDynamoDBException: ExpressionAttributeValues must not be empty. For example, this operation:

var ddb = new AmazonDynamoDBClient();
var table = new TableBuilder(ddb, "TestTable").AddHashKey("pk", DynamoDBEntryType.String).Build();
var doc = new Document { ["pk"] = Guid.NewGuid().ToString() };

await table.PutItemAsync(doc, new PutItemOperationConfig
{
    ConditionalExpression = new Expression { ExpressionStatement = "attribute_not_exists(pk)" },
});

Would result in the following request body:

{"ConditionExpression":"attribute_not_exists(pk)","ExpressionAttributeValues":{},"Item":{"pk":{"S":"386ba1d5-5b18-47e5-9c22-3b73e0f1ddd1"}},"TableName":"TestTable"}

This PR updates the document model to match the request sent by V3:

{"ConditionExpression":"attribute_not_exists(pk)","Item":{"pk":{"S":"75fbb295-a11c-4447-ac1a-bacc2baacd0c"}},"TableName":"TestTable"}

Testing

  • Dry-run: DRY_RUN-c628983c-fa45-42c4-a4d0-81921c146e4f
  • Also confirmed this works when AWSConfigs.InitializeCollections is set to true

Types of changes

  • Bug fix (non-breaking change which fixes an issue)

Checklist

  • My code follows the code style of this project
  • I have added tests to cover my changes
  • All new and existing tests passed

License

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

@dscpinheiro dscpinheiro requested a review from normj May 9, 2025 19:02
@dscpinheiro dscpinheiro added the v4 label May 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

DynamoDB Exception: ExpressionAttributeValues must not be empty, even when there are no variables
2 participants