Skip to content

Commit 4ab34ca

Browse files
Lita Chodanielhochman
authored andcommitted
make update_item respect attr_name differences (#160)
1 parent 5229759 commit 4ab34ca

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

pynamodb/models.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -349,12 +349,12 @@ def update_item(self, attribute, value=None, action=None, conditional_operator=N
349349
if len(expected_values):
350350
kwargs.update(expected=self._build_expected_values(expected_values, UPDATE_FILTER_OPERATOR_MAP))
351351
kwargs[pythonic(ATTR_UPDATES)] = {
352-
attribute: {
352+
attribute_cls.attr_name: {
353353
ACTION: action.upper() if action else None,
354354
}
355355
}
356356
if action is not None and action.upper() != DELETE:
357-
kwargs[pythonic(ATTR_UPDATES)][attribute][VALUE] = {ATTR_TYPE_MAP[attribute_cls.attr_type]: value}
357+
kwargs[pythonic(ATTR_UPDATES)][attribute_cls.attr_name][VALUE] = {ATTR_TYPE_MAP[attribute_cls.attr_type]: value}
358358
kwargs[pythonic(RETURN_VALUES)] = ALL_NEW
359359
kwargs.update(conditional_operator=conditional_operator)
360360
data = self._get_connection().update_item(

pynamodb/tests/test_model.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -900,6 +900,29 @@ def test_update_item(self):
900900
}
901901
deep_eq(args, params, _assert=True)
902902

903+
with patch(PATCH_METHOD) as req:
904+
item.update_item('custom_aliases', set(['lita']), action='add')
905+
args = req.call_args[0][1]
906+
params = {
907+
'TableName': 'SimpleModel',
908+
'ReturnValues': 'ALL_NEW',
909+
'Key': {
910+
'user_name': {
911+
'S': 'foo'
912+
}
913+
},
914+
'AttributeUpdates': {
915+
'aliases': {
916+
'Action': 'ADD',
917+
'Value': {
918+
'SS': set(['lita'])
919+
}
920+
}
921+
},
922+
'ReturnConsumedCapacity': 'TOTAL'
923+
}
924+
deep_eq(args, params, _assert=True)
925+
903926
def test_save(self):
904927
"""
905928
Model.save

0 commit comments

Comments
 (0)