moto icon indicating copy to clipboard operation
moto copied to clipboard

Dynamodb missing error with ADD empty set

Open jasonrdunne opened this issue 1 year ago • 3 comments

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 avatar Apr 14 '24 20:04 jasonrdunne

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}

jasonrdunne avatar May 11 '24 19:05 jasonrdunne

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"}},
        )

bblommers avatar May 11 '24 19:05 bblommers

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

roehlc avatar May 23 '24 08:05 roehlc

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

bblommers avatar Jun 02 '24 09:06 bblommers