Skip to content
This repository has been archived by the owner on May 10, 2024. It is now read-only.

Commit

Permalink
Merge branch 'ddb2-fix-has-item' into develop
Browse files Browse the repository at this point in the history
Fixes #2090.
  • Loading branch information
toastdriven committed Feb 11, 2014
2 parents c091d27 + d902a66 commit aada5d3
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
4 changes: 4 additions & 0 deletions boto/dynamodb2/exceptions.py
Expand Up @@ -72,3 +72,7 @@ class UnknownFilterTypeError(DynamoDBError):

class QueryError(DynamoDBError):
pass


class ItemNotFound(DynamoDBError):
pass
4 changes: 3 additions & 1 deletion boto/dynamodb2/table.py
Expand Up @@ -488,6 +488,8 @@ def get_item(self, consistent=False, attributes=None, **kwargs):
attributes_to_get=attributes,
consistent_read=consistent
)
if 'Item' not in item_data:
raise exceptions.ItemNotFound("Item %s couldn't be found." % kwargs)
item = Item(self)
item.load(item_data)
return item
Expand Down Expand Up @@ -526,7 +528,7 @@ def has_item(self, **kwargs):
"""
try:
self.get_item(**kwargs)
except JSONResponseError:
except (JSONResponseError, exceptions.ItemNotFound):
return False

return True
Expand Down
8 changes: 8 additions & 0 deletions tests/integration/dynamodb2/test_highlevel.py
Expand Up @@ -109,6 +109,14 @@ def test_integration(self):

time.sleep(5)

# Does it exist? It should?
self.assertTrue(users.has_item(username='jane', friend_count=3))
# But this shouldn't be there...
self.assertFalse(users.has_item(
username='mrcarmichaeljones',
friend_count=72948
))

# Test getting an item & updating it.
# This is the "safe" variant (only write if there have been no
# changes).
Expand Down

0 comments on commit aada5d3

Please sign in to comment.