{"action":"created","issue":{"url":"https://api.github.com/repos/boto/boto/issues/3241","labels_url":"https://api.github.com/repos/boto/boto/issues/3241/labels{/name}","comments_url":"https://api.github.com/repos/boto/boto/issues/3241/comments","events_url":"https://api.github.com/repos/boto/boto/issues/3241/events","html_url":"https://github.com/boto/boto/issues/3241","id":90388936,"number":3241,"title":"DynamoDB: item.save() on an object retrieved from a scan() updates ALL fields","user":{"login":"rix0rrr","id":524162,"avatar_url":"https://avatars.githubusercontent.com/u/524162?v=3","gravatar_id":"","url":"https://api.github.com/users/rix0rrr","html_url":"https://github.com/rix0rrr","followers_url":"https://api.github.com/users/rix0rrr/followers","following_url":"https://api.github.com/users/rix0rrr/following{/other_user}","gists_url":"https://api.github.com/users/rix0rrr/gists{/gist_id}","starred_url":"https://api.github.com/users/rix0rrr/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rix0rrr/subscriptions","organizations_url":"https://api.github.com/users/rix0rrr/orgs","repos_url":"https://api.github.com/users/rix0rrr/repos","events_url":"https://api.github.com/users/rix0rrr/events{/privacy}","received_events_url":"https://api.github.com/users/rix0rrr/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-06-23T13:27:08Z","updated_at":"2015-06-26T10:37:48Z","closed_at":null,"body":"The following happens while using `boto.dynamodb`.\r\n\r\nWhen I do something like this:\r\n\r\n    table = conn.get_table(...)\r\n    items = table.scan(...)\r\n    for item in items:\r\n        item['field'] = 10\r\n        item.save()\r\n\r\nThen the save() call will trigger an UpdateItem with ALL fields on the object in it, instead of just the field that I changed. Effectively, this turns my `save()` call into a `put()`.\r\n\r\nThis is because TableGenerator does the following:\r\n\r\n    class TableGenerator:\r\n        ...\r\n        def __iter__(self):\r\n            ...\r\n            for item in response.get('Items', []):\r\n                yield self.item_class(self.table, attrs=item)\r\n\r\nAnd the constructor of `boto.dynamodb.item.Item` looks like this:\r\n\r\n    class Item:\r\n        def __init__(self, table, hash_key=None, range_key=None, attrs=None):\r\n            ...\r\n            self._updates = None\r\n            ...\r\n            self._updates = {}\r\n            for key, value in attrs.items():\r\n                if key != self._hash_key_name and key != self._range_key_name:\r\n                    self[key] = value     # <-- this puts them into self._updates\r\n\r\nAnd when `item.save()` is called, it will save everything in `self._updates`.\r\n\r\nI.e., all attributes passed in the constructor will get queued up as updates, which are the same attributes that just got retrieved from the database. `get_item()` has the same problem.\r\n\r\nThe `_updates` array should be cleared for objects retrieved from the database."},"comment":{"url":"https://api.github.com/repos/boto/boto/issues/comments/115637511","html_url":"https://github.com/boto/boto/issues/3241#issuecomment-115637511","issue_url":"https://api.github.com/repos/boto/boto/issues/3241","id":115637511,"user":{"login":"rix0rrr","id":524162,"avatar_url":"https://avatars.githubusercontent.com/u/524162?v=3","gravatar_id":"","url":"https://api.github.com/users/rix0rrr","html_url":"https://github.com/rix0rrr","followers_url":"https://api.github.com/users/rix0rrr/followers","following_url":"https://api.github.com/users/rix0rrr/following{/other_user}","gists_url":"https://api.github.com/users/rix0rrr/gists{/gist_id}","starred_url":"https://api.github.com/users/rix0rrr/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rix0rrr/subscriptions","organizations_url":"https://api.github.com/users/rix0rrr/orgs","repos_url":"https://api.github.com/users/rix0rrr/repos","events_url":"https://api.github.com/users/rix0rrr/events{/privacy}","received_events_url":"https://api.github.com/users/rix0rrr/received_events","type":"User","site_admin":false},"created_at":"2015-06-26T10:37:48Z","updated_at":"2015-06-26T10:37:48Z","body":"You're speaking of the DynamoDBv2 interface, but my bug report is about the v1 interface.\r\n\r\nThe v1 docs suggest that this should work like I expect:\r\n\r\n\"save(...): Commits pending updates to Amazon DynamoDB.\"\r\n\r\nhttp://boto.readthedocs.org/en/latest/ref/dynamodb.html#module-boto.dynamodb.item\r\n\r\n\r\n"}}