boto / boto3

AWS SDK for Python
https://aws.amazon.com/sdk-for-python/
Apache License 2.0
8.99k stars 1.86k forks source link

dynamodb client.batch_get_item() fails in case keys contains duplicates #4131

Closed kanishthkarthik closed 4 months ago

kanishthkarthik commented 4 months ago

Describe the bug

Invoking batch_get_item with duplicate keys results in a ValidationException. I could not find a reference to this error either in the boto3 documentation or in the AWS Docs for BatchGetItem. Is this an expected behavior?

Expected Behavior

A ValidationException is not raised or the behavior is documented.

Current Behavior

Invoking batch_get_item with duplicate keys results in a ValidationException.

Reproduction Steps

import boto3

keys = [{'id': {'S': key}} for key in ['id1', 'id1', 'id2']]

client = boto3.client('dynamodb', region_name='us-east-1')
response = client.batch_get_item(
    RequestItems={'IdTable': {'Keys': keys}},
)

The above snippet raises: ClientError: An error occurred (ValidationException) when calling the BatchGetItem operation: Provided list of item keys contains duplicates

Possible Solution

The behavior can be detailed in the documentation.

Additional Information/Context

No response

SDK version used

1.34.76

Environment details (OS name and version, etc.)

macOS 14.4.1

tim-finnigan commented 4 months ago

Thanks for reaching out. This is the expected behavior. The Boto3 batch_get_item command involves a call to the underlying DynamoDB BatchGetItem API in which the ValidationException occurs. As mentioned in the documentation for Keys:

Keys - An array of primary key attribute values that define specific items in the table...

So Keys should correspond to specific items, and therefore duplicates cannot be used here. Hope that helps, if you have any follow up questions let us know. I'm going to convert this do a discussion as it is not a bug.

And if you think the documentation could be improved here please use the Provide feedback at the bottom of the API documentation page to reach the appropriate team. Any updates to the API docs will be updated in Boto3 automatically.

github-actions[bot] commented 4 months ago

This issue is now closed. Comments on closed issues are hard for our team to see. If you need more assistance, please open a new issue that references this one.