question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

dynamodb item update doesn't support UpdateExpression (SET)

See original GitHub issue

Documentation on UpdateExpression (SET):

http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.Modifying.html#Expressions.Modifying.UpdateExpressions.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:closed
  • Created 7 years ago
  • Reactions:2
  • Comments:9 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
ericman93commented, Mar 20, 2019

trying to use list_append

 table.update_item(
    Key={
        'request_id': unique_id
    },
    ExpressionAttributeValues={':file_name': ['ABC']},
    UpdateExpression='SET file_names = list_append(file_names, :file_name)'
)

but when I query dynamo later the value of file_names is list_append(file_names, :file_name) same issue when i’m trying to increment value, the value after I query is the update expression

1reaction
ryansydnorcommented, Sep 23, 2016

Seeing the same issue. Looks like if_not_exists and list_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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found