NodeJS DAX client doesn't support Update item having same field name with the condition expression.

0

Hello team,

So recently, I was trying to enable DAX instead of using the normal DynamoDB client. And I found this issue. When I'm issuing a Update with this:

"Update": {
        "Key": {
            "id": {
                "S": "de26b619-d3e1-4de9-a338-12f95780538f"
            }
        },
        "ConditionExpression": "#a0 = :v0 AND #a1 = :v1",
        "ExpressionAttributeNames": {
            "#a0": "tenantId",
            "#a1": "_version",
            "#a2": "updatedAt",
            "#a3": "_version",
            "#a4": "totalAmountOutstanding",
            "#a5": "items"
        },
        "ExpressionAttributeValues": {
            ":v0": {
                "S": "HelmTest"
            },
            ":v1": {
                "N": "1"
            },
            ":v2": {
                "N": "1650900411690"
            },
            ":v3": {
                "N": "2"
            },
           ...

So basically, I'm using the field _version to implement optimistic locking. When using DAX to run this update, I got the error:

{
    "errorType": "Error",
    "errorMessage": "ValidationException: Two document paths overlap with each other; must remove or rewrite one of these paths _version",
    "code": "ValidationException",
    "time": 1650900411978,
    "retryable": false,
    "requestId": null,
    "statusCode": -1,
    "_tubeInvalid": false,
    "waitForRecoveryBeforeRetrying": false,
    "stack": [
        "Error: ValidationException: Two document paths overlap with each other; must remove or rewrite one of these paths _version",
        "    at Function.newValidationException (/node_modules/amazon-dax-client/src/RequestValidator.js:383:12)",
        "    at /node_modules/amazon-dax-client/src/RequestValidator.js:84:34",
        "    at Array.forEach (<anonymous>)",
        "    at Function.validateExprAttrNames (/node_modules/amazon-dax-client/src/RequestValidator.js:78:30)",
        "    at Function.validateExpression (/node_modules/amazon-dax-client/src/RequestValidator.js:217:42)",
        "    at /node_modules/amazon-dax-client/src/BaseOperations.js:603:26",
        "    at processTicksAndRejections (internal/process/task_queues.js:95:5)",
        "    at p2 (/node_modules/dynamoose/lib/aws/ddb/internal.ts:30:17)",
        "    at /node_modules/dynamoose/lib/Transaction.ts:99:23",

The library complains that it won't allow me to use _version many times. I looked into the source code, and this is confirmed:

      let attrs = new Set();
      Object.keys(attrNames).forEach((k) => {
        let v = attrNames[k];
        if(k == null) {
          throw new AmazonClientException('ExpressionAttributeNames contains invalid key: null');
        }
        if(attrs.has(v)) {
          throw RequestValidator.newValidationException('Two document paths overlap with each other; must remove or rewrite one of these paths ' + v);
        }
        attrs.add(v);

I believe this is a bug in the library, as this is a normal use case and it should be allowed. For now, I've turned off the DAX and gone back to the normal DynamoDB client, where things are working.

asked 2 years ago360 views
2 Answers
1

Hi, Thanks for reaching out and bringing this to our attention. This is something the team are aware of and have already pushed a fix for the Java SDK. However, they have yet to bring the other SDK's up to speed. Unfortunately I do not have an ETA on this bug fix, but I have added your voice to the prioritization of it.

profile pictureAWS
EXPERT
answered 2 years ago
0

Hello, can you share with me the commit for the fix on your Java SDK? Thank you.

answered 2 years ago
  • The SDK is not open-source and I will not be able to provide you with a commit. The most recent version of the SDK in Java has the fix implemented.

    The DAX team will be providing the fix for NodeJS on the next release. As mentioned, I have no ETA on the push of the latest release.

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions