Skip to content

Loading…

Conditional put was causing "condition failed" error, even when the condition was met #517

Closed
wants to merge 1 commit into from

3 participants

@nishant123001

There are two kind of conditional puts in dynamodb
1. If attribute exists or not. Is is needed to be represented in the request as {"attr_name" : {"Exist" : } }
2. We can also check the value of the attribute and only change the data if that condition is met. e.g
for Item.put if expected_value is {"attr_name": "old_attr"}
Then "put: will only be successful if the "attr_name" attribute in the dynamodb was previously has value "old_attr"

The correct format for the request should be {"attr_name" : {"Value" : {"S" : "old_attr"} } }
but we were always sending it as {"attr_name" : {"S" : "old_attr"} } . hence the Item.put was always failing.

Nishant The conditional put requires attribute value to be inthe form {'Value…
…': dynamize_valu} we were directly passing dynamize_value.
053c469
@gtaylor

I don't suppose we could talk you into providing a unit test for this that shows the currently failing behavior? This would be invaluable in making sure we don't break this again.

@garnaat garnaat closed this in fd893b3
@msabramo msabramo pushed a commit to msabramo/boto that referenced this pull request
@garnaat garnaat Fix handling of Expected parameter. Closes #517. d144c7d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jan 25, 2012
  1. The conditional put requires attribute value to be inthe form {'Value…

    Nishant committed
    …': dynamize_valu} we were directly passing dynamize_value.
Showing with 1 addition and 1 deletion.
  1. 0 boto/dynamodb/item.py
  2. +1 −1 boto/dynamodb/layer2.py
View
0 boto/dynamodb/item.py 100644 → 100755
File mode changed.
View
2 boto/dynamodb/layer2.py 100644 → 100755
@@ -118,7 +118,7 @@ def dynamize_expected_value(self, expected_value):
elif attr_value is False:
attr_value = {'Exists': False}
else:
- attr_value = self.dynamize_value(expected_value[attr_name])
+ attr_value = {'Value' : self.dynamize_value(expected_value[attr_name])}
d[attr_name] = attr_value
return d
Something went wrong with that request. Please try again.