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

Setting ReturnValuesOnConditionCheckFailure does not return Item property in ConditionalCheckFailedException #3067

Closed
theGusPassos opened this issue Oct 10, 2023 · 3 comments
Assignees
Labels
bug This issue is a bug. dynamodb response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days.

Comments

@theGusPassos
Copy link

theGusPassos commented Oct 10, 2023

Describe the bug

When setting the ReturnValuesOnConditionCheckFailure to ALL_OLD the Item property inside ConditionalCheckFailedException is not being set.

Expected Behavior

The ConditionalCheckFailedException should return an Item property with the current value in the db.

Current Behavior

The value returned for the Item property is empty.

Reproduction Steps

            var request = new UpdateItemRequest
            {
                TableName = "table",
                Key = new Dictionary<string, AttributeValue>
                {
                    { "KEY", new AttributeValue { S = "1" } }
                },
                ConditionExpression = $"state" = :expectedState",
                ExpressionAttributeValues = _expressionAttributeValues,
                UpdateExpression = $"SET state = :newState",
                ReturnValuesOnConditionCheckFailure = ReturnValuesOnConditionCheckFailure.ALL_OLD,
               };

            try
            {
                var response = await _ddbClient.UpdateItemAsync(request);
                if (response?.HttpStatusCode == System.Net.HttpStatusCode.OK)
                {
                    return;
                }
            }
            catch (ConditionalCheckFailedException e)
            {
                var actualStateInDb = e.Item["state"].S;
            }

Possible Solution

No response

Additional Information/Context

Running Dynamo in local container.

AWS .NET SDK and/or Package version used

AWSSDK.DynamoDBv2 3.7.203.1

Targeted .NET Platform

net7.0

Operating System and version

Windows 11

@theGusPassos theGusPassos added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Oct 10, 2023
@bhoradc bhoradc self-assigned this Oct 12, 2023
@bhoradc bhoradc added dynamodb and removed needs-triage This issue or PR still needs to be triaged. labels Oct 12, 2023
@bhoradc
Copy link

bhoradc commented Oct 13, 2023

Hi @theGusPassos,

Thanks for reporting the issue. But I am unable to replicate the behaviour. Using the AWSSDK.DynamoDBv2 3.7.203.1 package, I am able to get the existing item property value on the ConditionalCheckFailedException.
Also, not sure how the reserved keyword 'state' is allowed for an attribute name in your program.

Here's the code that I used:

 try
 {
     AmazonDynamoDBClient client = new AmazonDynamoDBClient();

     var request = new UpdateItemRequest
     {
         TableName = "table",
         Key = new Dictionary<string, AttributeValue>() { { "KEY", new AttributeValue { S = "1" } } },

         ConditionExpression = $"flag = :expectedState",
         
         ExpressionAttributeValues = new Dictionary<string, AttributeValue>()
         {
             { ":newState", new AttributeValue { S = "inactive" } },
             { ":expectedState", new AttributeValue { S = "active" } }
         },
         UpdateExpression = $"SET flag = :newState",
         ReturnValuesOnConditionCheckFailure = Amazon.DynamoDBv2.ReturnValuesOnConditionCheckFailure.ALL_OLD,

     };

     var response = await client.UpdateItemAsync(request);
     if (response?.HttpStatusCode == System.Net.HttpStatusCode.OK)
     {
         return;
     }
 }
 catch (ConditionalCheckFailedException e)
 {
     var actualStateInDb = e.Item["flag"].S;
     Console.WriteLine(actualStateInDb);
 }

Execution Result: inactive

Can you please share the _expressionAttributeValues details? And also maybe the exact output you are getting?

Regards,
Chaitanya

@bhoradc bhoradc added the response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. label Oct 13, 2023
@theGusPassos
Copy link
Author

@bhoradc apparently the error only happens when hitting my local dynamo db, even though its using the latest version...
When I hit one in aws, it returns the actual value.

@github-actions
Copy link

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue is a bug. dynamodb response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days.
Projects
None yet
Development

No branches or pull requests

2 participants