New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ensure Model.update accounts for REMOVE expressions on in memory object #741
Conversation
f78b089
to
754ef86
Compare
@@ -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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that this assertion always passed since views
was never set.
This is also a breaking change for anyone relying on the attribute still being set even after the db update. Any guidance on what version we'd need to introduce this? |
Does foop = SimpleUserModel(
user_name='foop',
email='foop@geep.com',
is_active=True,
views=5,
)
foop.save()
foop.update(
actions=[
SimpleUserModel.is_active.set(False),
SimpleUserModel.views.remove(),
]
) will |
Yes, |
@jpinner-lyft Maybe I'm remembering wrong but I feel we had another issue with deserialization being guided by the server's response rather than the model's attributes. |
Spent some time testing this and generally seems good. If we do allow customization of One odd thing, which is an existing issue, is that you can unset an attribute which omits @ikonst the main thing I could think of was the handling of |
I don't see any problem with this behavior. In general I'd like what we call "default" today to start behaving as "default_for_new" (defaults for when the object is constructed by the user), rather the way it's today - fallbacks for missing values, whether from user or from network. |
If an
UpdateItem
removes an attribute on an item in the db, this update is not reflected on the in memory object after the request succeeds.We request
RETURN_VALUES
asALL_NEW
during an update. DynamoDB will return the current state of all attributes asAttributes
in the response.Before this PR, we iterate over all of the returned attributes and assign them to the in memory copy of the item. This fails to account for an attribute that was removed via the
UpdateItem
request e.g.In this PR, we leverage
Model._deserialize
to iterate over the model's attributes, and pull each attribute out of the responseAttributes
. We expect the above example to execute as: