Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamodb missing error with ADD empty set #7595

Closed
jasonrdunne opened this issue Apr 14, 2024 · 4 comments · Fixed by #7742
Closed

Dynamodb missing error with ADD empty set #7595

jasonrdunne opened this issue Apr 14, 2024 · 4 comments · Fixed by #7742

Comments

@jasonrdunne
Copy link

This error is caught by aws, but not with moto:

ExpressionAttributeValues contains invalid value: One or more parameter values were invalid: An number set may not be empty for key :deletedConversationIds

It's caused by an update like this:

        user_table.update_item(
            TableName="Users",
            Key={"userId": user_id},
            UpdateExpression="ADD stringSet :emptySet",
            ExpressionAttributeValues={
                ":emptySet": empty_set,
            },
        )
@jasonrdunne
Copy link
Author

I found another similar issue:

if an ExpressionAttributeValue is defined and not used, it errors in real aws, but not moto:

Value provided in ExpressionAttributeValues unused in expressions: keys: {:variable}

@bblommers
Copy link
Collaborator

Hi @jasonrdunne, thanks for raising these! I'll open a PR to add validation for the first issue in a second.

Do you have an example for the second issue? The following code does throw an error in Moto:

dynamodb.update_item(
            TableName=table_name,
            Key={"pk": {"S": "foo"}},
            UpdateExpression="ADD stringset :emptySet",
            ExpressionAttributeValues={":emptySet": {"SS": ()}, "other": {"S": "data"}},
        )

@roehlc
Copy link

roehlc commented May 23, 2024

I also ran into a similar issue, analogue to the issue @jasonrdunne described. My update_item call looks like this:

        db_response = table.update_item(
            Key={
                'shortid': tenant_id
            },
            UpdateExpression="SET spec.#limit = :limit",
            ExpressionAttributeNames={
                "#count": "count",
                "#limit": "limit"
            },
            ExpressionAttributeValues={
                ":countChange": 1,
                ":limit": limit
            },
            ConditionExpression="attribute_exists(shortid)",
            ReturnValues="ALL_NEW"
        )

And real AWS throws the error:
'Message': 'Value provided in ExpressionAttributeNames unused in expressions: keys: {#count}',
'Code': 'ValidationException'

while moto does not throw an error

@bblommers
Copy link
Collaborator

Thanks for letting us know @roehlc - the attached PR will add that validation to Moto.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants