Skip to content

Commit b45f4a9

Browse files
conjmurphgarrettheel
authored andcommitted
Ensure Model.update accounts for REMOVE expressions on in-memory object (#741)
1 parent 8fb65e0 commit b45f4a9

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

pynamodb/models.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -390,11 +390,7 @@ def update(self, actions, condition=None):
390390
kwargs.update(actions=actions)
391391

392392
data = self._get_connection().update_item(*args, **kwargs)
393-
for name, value in data[ATTRIBUTES].items():
394-
attr_name = self._dynamo_to_python_attr(name)
395-
attr = self.get_attributes().get(attr_name)
396-
if attr:
397-
setattr(self, attr_name, attr.deserialize(attr.get_value(value)))
393+
self._deserialize(data[ATTRIBUTES])
398394
return data
399395

400396
def save(self, condition=None):

tests/test_model.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -837,7 +837,7 @@ def test_update(self, mock_time):
837837
"""
838838
mock_time.side_effect = [1559692800] # 2019-06-05 00:00:00 UTC
839839
self.init_table_meta(SimpleUserModel, SIMPLE_MODEL_TABLE_DATA)
840-
item = SimpleUserModel('foo', is_active=True, email='foo@example.com', signature='foo')
840+
item = SimpleUserModel(user_name='foo', is_active=True, email='foo@example.com', signature='foo', views=100)
841841

842842
with patch(PATCH_METHOD) as req:
843843
req.return_value = {}
@@ -848,12 +848,18 @@ def test_update(self, mock_time):
848848
with patch(PATCH_METHOD) as req:
849849
req.return_value = {
850850
ATTRIBUTES: {
851+
"user_name": {
852+
"S": "foo",
853+
},
851854
"email": {
852855
"S": "foo@example.com",
853856
},
854857
"is_active": {
855858
"NULL": None,
856859
},
860+
"signature": {
861+
"NULL": None,
862+
},
857863
"aliases": {
858864
"SS": {"bob"},
859865
}

0 commit comments

Comments
 (0)