Skip to content

Commit

Permalink
Allow an Item to be created without a hash/range key to handle situat…
Browse files Browse the repository at this point in the history
…ion where attributes_to_get does not include hash/range. Fixes boto#656.
  • Loading branch information
garnaat committed Apr 30, 2012
1 parent 607f588 commit ad0ccad
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 16 deletions.
11 changes: 2 additions & 9 deletions boto/dynamodb/item.py
Expand Up @@ -41,15 +41,8 @@ def __init__(self, table, hash_key=None, range_key=None, attrs=None):
self._updates = None
self._hash_key_name = self.table.schema.hash_key_name
self._range_key_name = self.table.schema.range_key_name
if hash_key is None:
if attrs.get(self._hash_key_name) is None:
raise DynamoDBItemError('You must supply a hash_key')
hash_key = attrs[self._hash_key_name]
if self._range_key_name:
if range_key is None:
if attrs.get(self._range_key_name) is None:
raise DynamoDBItemError('You must supply a range_key')
range_key = attrs[self._range_key_name]
hash_key = hash_key or attrs.get(self._hash_key_name, None)
range_key = range_key or attrs.get(self._range_key_name, None)
self[self._hash_key_name] = hash_key
if self._range_key_name:
self[self._range_key_name] = range_key
Expand Down
7 changes: 0 additions & 7 deletions tests/dynamodb/test_layer2.py
Expand Up @@ -102,13 +102,6 @@ def test_layer2_basic(self):
'LastPostDateTime': '12/9/2011 11:36:03 PM'}

# Test a few corner cases with new_item
# First, try not supplying a hash_key
self.assertRaises(DynamoDBItemError,
table.new_item, None, item1_range, item1_attrs)

# Try supplying a hash but no range
self.assertRaises(DynamoDBItemError,
table.new_item, item1_key, None, item1_attrs)

# Try supplying a hash_key as an arg and as an item in attrs
item1_attrs[hash_key_name] = 'foo'
Expand Down

0 comments on commit ad0ccad

Please sign in to comment.