boto3 icon indicating copy to clipboard operation
boto3 copied to clipboard

ParamValidationError when using DynamoDB paginator

Open usegev opened this issue 5 years ago • 12 comments

I create a DynamoDB paginator like this:

    paginator = client.get_paginator('query')
    page_iterator = paginator.paginate(
        TableName=TABLE_NAME,
        IndexName=INDEX_NAME,
        KeyConditionExpression=Key('X').eq(x) & Key('Y').lte(y)
    )
    for page in page_iterator:
        print (page['Items'])
    return

When I run it, I receive the following error:

Exception has occurred: ParamValidationError
Parameter validation failed:
Invalid type for parameter KeyConditionExpression, value: <boto3.dynamodb.conditions.And object at 0x111524110>, type: <class 'boto3.dynamodb.conditions.And'>, valid types: <class 'str'>

The exact same KeyConditionExpression works when I query the table directly:

    result = table.query(
        IndexName=INDEX_NAME,
        KeyConditionExpression=Key('X').eq(x) & Key('Y').lte(y)
    )

BTW: Documentation says that KeyConditionExpression should be a string and not some condition built this way.

usegev avatar Feb 20 '20 11:02 usegev

@usegev - Thank you for your post. I am able to reproduce the issue. Looking into it.

swetashre avatar Feb 20 '20 19:02 swetashre

@usegev - We have a customization around resources that converts KeyConditionExpression type to string format that's why you are not getting error when query the table directly.

You can use the same format with paginator by using resource.meta.client. Something like this:

import boto3
res = boto3.resource('dynamodb')

paginator = res.meta.client.get_paginator('query')
page_iterator = paginator.paginate(
        TableName=TABLE_NAME,
        IndexName=INDEX_NAME,
        KeyConditionExpression=Key('X').eq(x) & Key('Y').lte(y)
    )

Hope it helps and please let me know if you have any questions.

swetashre avatar Feb 24 '20 19:02 swetashre

Thanks @swetashre, works as you described. Will the documentation be updated? Or will the client paginator support it as well?

usegev avatar Feb 26 '20 12:02 usegev

We are tracking this issue internally. We are working to document this behavior.

swetashre avatar Feb 26 '20 23:02 swetashre

thanks @swetashre this was making me scratch my head

saintross avatar Apr 16 '20 15:04 saintross

I am having the same issue with KeyConditionExpression for query and paginator

dynamodb = boto3.client('dynamodb',  . . . )
items = dynamodb.query(TableName='test',
    KeyConditionExpression=Key('user_email').eq('[email protected]'))

using paginator:

paginator = dynamodb.get_paginator('query')
items = paginator.paginate(TableName='test',
    KeyConditionExpression=Key('user_email').eq('[email protected]'))

getting:

Invalid type for parameter KeyConditionExpression,
value: <boto3.dynamodb.conditions.Equals object at 0x7f286128e990>,
type: <class 'boto3.dynamodb.conditions.Equals'>, valid types: <class 'str'>

kulbida avatar Apr 17 '20 16:04 kulbida

What is the status on this issue ?

ChetanaYogeesh-zz avatar May 20 '20 01:05 ChetanaYogeesh-zz

I'm having this same problem.

alexsanderp avatar Jun 15 '20 15:06 alexsanderp

Any updates on this? I'm getting the same issue as @kulbida

ianscottknight avatar Apr 18 '21 19:04 ianscottknight

Any update?

koren-at-fundbox avatar Jun 06 '21 09:06 koren-at-fundbox

I am having the same issue on October 2021

sebas-nicholls avatar Oct 20 '21 02:10 sebas-nicholls

response = client.query( TableName=table_name, IndexName="user_id", KeyConditionExpression="user_id = :user_id", ExpressionAttributeValues= { ":user_id": { "S": "XYZ" } } )

This works for me!

aadidubey7 avatar Apr 21 '22 09:04 aadidubey7