question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[BUG] ValidationException: Either the KeyConditions or KeyConditionExpression parameter must be specified in the request

See original GitHub issue

Summary:

I am getting the below error. Even though, GSI is configured in the schema.

Code sample:

Schema

const serviceDefinitionSchema = new dynamoose.Schema(
    {
        serviceId: {
            type: String,
            hashKey: true,
            index: true,
        }, // primary key/Hash key
        context: String,
        contextId: {
            type: String,
            index: [
                {
                    global: true,
                    rangeKey: 'serviceId',
                    name: 'contextId-serviceId-index',
                    project: true, // ProjectionType: ALL
                },
                {
                    global: true,
                    rangeKey: 'serviceName',
                    name: 'contextId-serviceName-index',
                    project: true, // ProjectionType: ALL
                },
            ],
        },
        hotelId: {
            type: String,
            index: {
                global: true,
                rangeKey: 'serviceName',
                name: 'hotelId-serviceName-index',
                project: true, // ProjectionType: ALL
                // throughput: 1, // read and write are both 1
            },
        },
        serviceName: String,
        removal: Boolean, // If true, then treat it as Deleted
        isActive: Boolean, // Default: 1
    },
    {
        timestamps: {
            createdAt: 'createDateTime',
            updatedAt: 'lastModifyDateTime',
        },
    }
);

Model

export const ModelOptions = {
    create: true,
    throughput: {
        read: 1,
        write: 1,
    },
    waitForActive: {
        enabled: true,
        check: {
            timeout: 180000,
            frequency: 1000,
        },
    },
    update: false,
};

export const ServiceDefinitionEntity = dynamoose.model(
    process.env.SERVICES_DEFINITION_TABLE ?? 'Appsync-ServicesDefinition',
    serviceDefinitionSchema,
    ModelOptions
);

General

// query
const data = await ServiceDefinitionEntity.query({
            contextId: { eq: sContextId },
        })
            .using('contextId-serviceName-index')
            .where('serviceName')
            .eq(sServiceName)
            // @ts-expect-error
            .exec()
            .catch((error: any) => {
                tools.logError(`s-d.repo > getItemByContextIdAndServiceName > error:`, error);
                throw error;
            });

        tools.logDebug(`s-d.repo > getItemByContextIdAndServiceName > data:`, data);
        return data;

Current output and behavior (including stack trace):

Using above Schema, Model and Query. It throws below error.

s-d.repo > getItemByContextIdAndServiceName > error: ValidationException: Either the KeyConditions or KeyConditionExpression parameter must be specified in the request.
    at Request.extractError (D:\misc\htdocs\spider\hotelservices_service\node_modules\aws-sdk\lib\protocol\json.js:51:27)
    at Request.callListeners (D:\misc\htdocs\spider\hotelservices_service\node_modules\aws-sdk\lib\sequential_executor.js:106:20)
    at Request.emit (D:\misc\htdocs\spider\hotelservices_service\node_modules\aws-sdk\lib\sequential_executor.js:78:10)
    at Request.emit (D:\misc\htdocs\spider\hotelservices_service\node_modules\aws-sdk\lib\request.js:688:14)
    at Request.transition (D:\misc\htdocs\spider\hotelservices_service\node_modules\aws-sdk\lib\request.js:22:10)
    at AcceptorStateMachine.runTo (D:\misc\htdocs\spider\hotelservices_service\node_modules\aws-sdk\lib\state_machine.js:14:12)
    at D:\misc\htdocs\spider\hotelservices_service\node_modules\aws-sdk\lib\state_machine.js:26:10
    at Request.<anonymous> (D:\misc\htdocs\spider\hotelservices_service\node_modules\aws-sdk\lib\request.js:38:9)
    at Request.<anonymous> (D:\misc\htdocs\spider\hotelservices_service\node_modules\aws-sdk\lib\request.js:690:12)
    at Request.callListeners (D:\misc\htdocs\spider\hotelservices_service\node_modules\aws-sdk\lib\sequential_executor.js:116:18) {
  code: 'ValidationException',
  time: 2020-08-12T18:07:55.735Z,
  requestId: '9N1VFN8MDRJ8P0659VJVJGPCBJVV4KQNSO5AEMVJF66Q9ASUAAJG',
  statusCode: 400,
  retryable: false,
  retryDelay: 25.984542144410383
}

Expected output and behavior:

It should work as it is working while using hotelId-serviceName-index GSI in the query.

[AWS dynamodb 200 0.462s 0 retries] query({
  ExpressionAttributeNames: { '#qha': 'hotelId', '#qra': 'serviceName' },
  ExpressionAttributeValues: { ':qhv': { S: 'H123456' }, ':qrv': { S: 'Breakfast' } },
  TableName: 'Appsync-ServicesDefinition',
  IndexName: 'hotelId-serviceName-index',
  KeyConditionExpression: '#qha = :qhv AND #qra = :qrv'
})

Environment:

Operating System: Windows Operating System Version: 10 Node.js version (node -v): 12.16.3 NPM version: (npm -v): 6.14.4 Dynamoose version: 2.3.0

Other information (if applicable):

Other:

  • I have read through the Dynamoose documentation before posting this issue
  • I have searched through the GitHub issues (including closed issues) and pull requests to ensure this issue has not already been raised before
  • I have searched the internet and Stack Overflow to ensure this issue hasn’t been raised or answered before
  • I have tested the code provided and am confident it doesn’t work as intended
  • I have filled out all fields above
  • I am running the latest version of Dynamoose

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:5
  • Comments:21 (7 by maintainers)

github_iconTop GitHub Comments

7reactions
fishcharliecommented, Feb 15, 2021

Please keep this discussion focused and on topic. If you don’t have anything to add to this topic, please refrain from commenting. To show your interest in this issue please consider liking the original issue with a 👍 as opposed to commenting.

If there were updates, I would have posted them here. This is an open source project. So anyone is welcome to contribute and submit a pull request for this issue.

In the event this thread continues to receive off topic comments, I will be locking this thread.

1reaction
flisboaccommented, May 20, 2021

@fishcharlie @lmanerich In 2.7.3, now the error changed to:

ValidationException: Filter Expression can only contain non-primary key attributes: Primary key attribute: columnA

The library is probably constructing the operation parameters wrong. Query’s documentation reads:

A filter expression cannot contain partition key or sort key attributes.

Read more comments on GitHub >

github_iconTop Results From Across the Web

KeyConditionExpression parameter must be specified in the ...
ValidationException (client): Either the KeyConditions or KeyConditionExpression parameter must be specified in the request. - {"__type":"com.
Read more >
KeyConditions - Amazon DynamoDB - AWS Documentation
For a query on a table, you can have conditions only on the table primary key attributes. You must provide the partition key...
Read more >
C# – Dynamodb error : Either the keyconditions or ... - iTecNote
Either the KeyConditions or KeyConditionExpression parameter must be specified in the request. I have specified the condition in a filter object. Why am...
Read more >
[BUG] ValidationException: Either the ... - Bountysource
[BUG] ValidationException: Either the KeyConditions or KeyConditionExpression parameter must be specified in the request.
Read more >
Dynamodb Error: Either The Keyconditions Or ... - ADocLib
[BUG] ValidationException: Either the KeyConditions or KeyConditionExpression parameter must be specified in the request. 2d ago. 1 comments. The item size ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found