PynamoDB icon indicating copy to clipboard operation
PynamoDB copied to clipboard

Conditional update trouble

Open ghost opened this issue 11 years ago • 2 comments

Using the update_item() method in the Model class in pynamodb.models is a giving me trouble. If I don't pass an action argument, it defaults to None and then when it hits action.upper() in this part of update_item()

        kwargs[pythonic(ATTR_UPDATES)] = {
            attribute: {
                ACTION: action.upper(),
                VALUE: {
                    ATTR_TYPE_MAP[attribute_cls.attr_type]: value
                }
            }
        }

the method fails. Shouldn't the action argument be required, if it defaults to None and then crashes because it is the default value?

ghost avatar Mar 03 '15 21:03 ghost

I think this fix caused a big issue to update item. The range key is missing in update_item function.

args, _ = self._get_save_args(null_check=False) kwargs = {}

See the range key is not in kwargs in this case.

kyangmove avatar Apr 23 '15 19:04 kyangmove

kwargs = {} if len(expected_values): kwargs.update(expected=self._build_expected_values(expected_values, UPDATE_FILTER_OPERATOR_MAP)) kwargs[pythonic(ATTR_UPDATES)] = { attribute: { ACTION: action.upper() if action else None, VALUE: { ATTR_TYPE_MAP[attribute_cls.attr_type]: value } } } kwargs[pythonic(RETURN_VALUES)] = ALL_NEW kwargs.update(conditional_operator=conditional_operator) data = self._get_connection().update_item( _args, *_kwargs )

kyangmove avatar Apr 23 '15 19:04 kyangmove