Created
March 24, 2015 11:00
-
-
Save sugiki/52453c449899141e7994 to your computer and use it in GitHub Desktop.
ADD operation patch for boto.dynamodb2.items.Item
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- /usr/local/lib/python2.7/site-packages/boto/dynamodb2/items.py.bak 2015-03-24 17:46:20.000000000 +0900 | |
+++ /usr/local/lib/python2.7/site-packages/boto/dynamodb2/items.py 2015-03-24 18:29:56.000000000 +0900 | |
@@ -1,5 +1,5 @@ | |
from copy import deepcopy | |
- | |
+from decimal import Decimal | |
class NEWVALUE(object): | |
# A marker for new data added. | |
@@ -352,9 +352,22 @@ | |
fields.add(key) | |
for key, value in alterations['changes'].items(): | |
+ # fix to add | |
+ action = 'PUT' | |
+ value = self._data[key] | |
+ org_value = self._orig_data[key] | |
+ if type(value) == type(org_value): | |
+ if type(value) == list: | |
+ if org_value == value[:len(org_value)]: # values have been changed | |
+ action = 'ADD' | |
+ value = value[len(org_value):] | |
+ elif type(value) in (set, int, float, Decimal): | |
+ action = 'ADD' | |
+ value = value - org_value | |
+ | |
final_data[key] = { | |
- 'Action': 'PUT', | |
- 'Value': self._dynamizer.encode(self._data[key]) | |
+ 'Action': action, | |
+ 'Value': self._dynamizer.encode(value) | |
} | |
fields.add(key) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment