boto3
boto3 copied to clipboard
ParamValidationError when using DynamoDB paginator
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 - Thank you for your post. I am able to reproduce the issue. Looking into it.
@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.
Thanks @swetashre, works as you described. Will the documentation be updated? Or will the client paginator support it as well?
We are tracking this issue internally. We are working to document this behavior.
thanks @swetashre this was making me scratch my head
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'>
What is the status on this issue ?
I'm having this same problem.
Any updates on this? I'm getting the same issue as @kulbida
Any update?
I am having the same issue on October 2021
response = client.query( TableName=table_name, IndexName="user_id", KeyConditionExpression="user_id = :user_id", ExpressionAttributeValues= { ":user_id": { "S": "XYZ" } } )
This works for me!