dynamodb item update doesn't support UpdateExpression (SET)
See original GitHub issueDocumentation on UpdateExpression (SET):
Exception:
self = Item: {'Attributes': {'Hk': {'S': 'queue_name:0'}, 'Rk': {'S': '4I7CaHMQPNhhGkv_AyOCyP61QYZJETkyEccZletk'}}}
update_expression = 'SET MT = if_not_exists(MT, :message_type), MC = if_not_exists(MC, :message_content), SI = if_not_exists(SI, :sender_i...first_visible_time), RT = if_not_exists(RT, :minus_1), RC = if_not_exists(RC, :zero), DT = if_not_exists(DT, :minus_1)'
expression_attribute_names = {}
expression_attribute_values = {':first_visible_time': {'N': '63608879137.886993408203125'}, ':message_content': {'S': '$'}, ':message_type': {'S': '$type_0'}, ':minus_1': {'N': '-1'}, ...}
def update(self, update_expression, expression_attribute_names, expression_attribute_values):
ACTION_VALUES = ['SET', 'set', 'REMOVE', 'remove']
action = None
for value in update_expression.split():
if value in ACTION_VALUES:
# An action
action = value
continue
else:
# A Real value
value = value.lstrip(":").rstrip(",")
for k, v in expression_attribute_names.items():
value = value.replace(k, v)
if action == "REMOVE" or action == 'remove':
self.attrs.pop(value, None)
elif action == 'SET' or action == 'set':
> key, value = value.split("=")
E ValueError: need more than 1 value to unpack
Specifically, it’s having trouble parsing this:
SET MT = if_not_exists(MT, :message_type), MC = if_not_exists(MC, :message_content), SI = if_not_exists(SI, :sender_id), ST = if_not_exists(ST, :now), FV = if_not_exists(FV, :first_visible_time), NV = if_not_exists(NV, :first_visible_time), RT = if_not_exists(RT, :minus_1), RC = if_not_exists(RC, :zero), DT = if_not_exists(DT, :minus_1)
Hk is the hash key and Rk is the range key.
Sorry I haven’t written a simple test case that reproduces the error. I’m at work and I need to move on to other things.
I produced this error on commit ea319698aab8c8e1c6f55d4e115808c725bac268 of moto.
Issue Analytics
- State:
- Created 7 years ago
- Reactions:2
- Comments:9 (2 by maintainers)
Top Results From Across the Web
Update expressions - Amazon DynamoDB
An update expression specifies how UpdateItem will modify the attributes of an item—for example, setting a scalar value or removing elements from a...
Read more >can't update item in DynamoDB - Stack Overflow
It looks like you are trying to update an item by using an Expression, and in this case, your UpdateExpression is incorrect.
Read more >[Solved] DynamoDB Update Not Working - Dynobase
It is probably an error in your UpdateExpression , or you are making a mistake somewhere in updateItem() . Solution: Here's How To...
Read more >dynamodb_update_item function - RDocumentation
Similarly, if you use ADD for an existing item to increment or decrement an attribute value that doesn't exist before the update, DynamoDB...
Read more >Ensuring Data Integrity with DynamoDB - Jeremy Daly
This means that if you try to update an item that doesn't exist, ... that to generate an UpdateExpression with the right combination...
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 FreeTop 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
Top GitHub Comments
trying to use
list_append
but when I query dynamo later the value of
file_names
islist_append(file_names, :file_name)
same issue when i’m trying to increment value, the value after I query is the update expressionSeeing the same issue. Looks like
if_not_exists
andlist_append
operations are not supported yet. Furthermore, after splitting on the=
sign there’s a possibility for both the key and value to have spurious whitespace. I’d recommend trimming them.