Skip to content

Commit

Permalink
Ensure Model.update accounts for REMOVE expressions on in-memory obje…
Browse files Browse the repository at this point in the history
…ct (#741)
  • Loading branch information
conjmurph authored and garrettheel committed Jan 23, 2020
1 parent 8fb65e0 commit b45f4a9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
6 changes: 1 addition & 5 deletions pynamodb/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -390,11 +390,7 @@ def update(self, actions, condition=None):
kwargs.update(actions=actions)

data = self._get_connection().update_item(*args, **kwargs)
for name, value in data[ATTRIBUTES].items():
attr_name = self._dynamo_to_python_attr(name)
attr = self.get_attributes().get(attr_name)
if attr:
setattr(self, attr_name, attr.deserialize(attr.get_value(value)))
self._deserialize(data[ATTRIBUTES])
return data

def save(self, condition=None):
Expand Down
8 changes: 7 additions & 1 deletion tests/test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -837,7 +837,7 @@ def test_update(self, mock_time):
"""
mock_time.side_effect = [1559692800] # 2019-06-05 00:00:00 UTC
self.init_table_meta(SimpleUserModel, SIMPLE_MODEL_TABLE_DATA)
item = SimpleUserModel('foo', is_active=True, email='foo@example.com', signature='foo')
item = SimpleUserModel(user_name='foo', is_active=True, email='foo@example.com', signature='foo', views=100)

with patch(PATCH_METHOD) as req:
req.return_value = {}
Expand All @@ -848,12 +848,18 @@ def test_update(self, mock_time):
with patch(PATCH_METHOD) as req:
req.return_value = {
ATTRIBUTES: {
"user_name": {
"S": "foo",
},
"email": {
"S": "foo@example.com",
},
"is_active": {
"NULL": None,
},
"signature": {
"NULL": None,
},
"aliases": {
"SS": {"bob"},
}
Expand Down

0 comments on commit b45f4a9

Please sign in to comment.