mock_dynamodb2 fails to update field that is used in a Global Secondary Index
See original GitHub issueIn the newest version of moto 2.0.1, when calling update_item on a field that is used as a key in a GSI, the operation triggers a ValidationException saying that an AttributeValue may not contain an empty string.
how to reproduce the issue
Save the following code to .py file and run.
from moto import mock_dynamodb2
import boto3
with mock_dynamodb2():
name = "TestTable"
conn = boto3.client("dynamodb", region_name="eu-west-2", aws_access_key_id="ak", aws_secret_access_key="sk")
conn.create_table(
TableName=name,
KeySchema=[{"AttributeName": "main_key", "KeyType": "HASH"}],
AttributeDefinitions=[{"AttributeName": "main_key", "AttributeType": "S"},
{"AttributeName": "index_key", "AttributeType": "S"}],
ProvisionedThroughput={"ReadCapacityUnits": 5, "WriteCapacityUnits": 5},
GlobalSecondaryIndexes=[
{
"IndexName": "test_index",
"KeySchema": [
{
"AttributeName": "index_key",
"KeyType": "HASH"
}
],
"Projection": {
"ProjectionType": "ALL",
},
"ProvisionedThroughput": {"ReadCapacityUnits": 1, "WriteCapacityUnits": 1}
}
]
)
conn.put_item(
TableName=name,
Item={
"main_key": {"S": "testkey1"},
"extra_data": {"S": "testdata"},
"index_key": {"S": "indexkey1"}
},
)
resp = conn.update_item(
TableName=name,
Key={"main_key": {"S": "testkey1"}},
UpdateExpression="set index_key=:new_index_key",
ExpressionAttributeValues={":new_index_key": {"S": "new_value"}}
)
print(resp)
what you expected to happen That the attribute index_key updates successfully.
I have validated that this code runs correctly against dynamodb proper without issues. It also works under the 1.3.6 version of moto.
what actually happens
Traceback (most recent call last):
File "test.py", line 41, in <module>
resp = conn.update_item(
File "/home/h0wser/.local/lib/python3.8/site-packages/botocore/client.py", line 357, in _api_call
return self._make_api_call(operation_name, kwargs)
File "/home/h0wser/.local/lib/python3.8/site-packages/botocore/client.py", line 676, in _make_api_call
raise error_class(parsed_response, operation_name)
botocore.exceptions.ClientError: An error occurred (ValidationException) when calling the UpdateItem operation: One or more parameter values were invalid: An AttributeValue may not contain an empty string
what version of Moto you’re using
boto==2.49.0
boto3==1.17.22
botocore==1.20.22
moto==2.0.1
Installed via pip.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:7 (1 by maintainers)
Top Results From Across the Web
Managing Global Secondary Indexes - Amazon DynamoDB
To create a table with one or more global secondary indexes, use the CreateTable operation with the GlobalSecondaryIndexes parameter.
Read more >DynamoDb update fails with error "The update expression ...
It fails with the error message "The update expression attempted to update the secondary index key to unsupported type". But the fields I'm ......
Read more >Step 6: Create a global secondary index - Amazon DynamoDB
Learn how to create a global secondary index (GSI) for a DynamoDB table using the ... The index is ready for use when...
Read more >Global Secondary Indexes - Jayendra's Cloud Certification Blog
AWS DynamoDB · A composite primary key is composed of two attributes. · The partition key value is used as input to an...
Read more >DynamoDB - Global Secondary Indexes - Tutorialspoint
Use KEYS_ONLY for infrequent table queries and frequent writes/updates. This controls size, but still offers good performance on queries. Global Secondary Index ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
This is now part of moto >= 2.0.10 @JamesBelchamber
That will depend on when another maintainer approves the fix @JamesBelchamber - I have no control over that timeline I’m afraid