Reputation: 19361
I've got a DynamoDB database set up with string hash key and range keys. This works:
>>> x = table.query(hash_key='[email protected]', range_key_condition=BEGINS_WITH("20"),
request_limit=5)
>>> [i for i in x]
[{u'x-entry-page': ...
This doesn't, and I can't figure out why not:
>>> x = table.query(hash_key='[email protected]', range_key_condition=BEGINS_WITH("20"),
attributes_to_get=[u'x-start-time'], request_limit=5)
>>> [i for i in x]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Library/Frameworks/Python.framework/Versions/7.2/lib/python2.7/site-packages/boto-2.3.0-py2.7.egg/boto/dynamodb/layer2.py", line 588, in query
yield item_class(table, attrs=item)
File "/Library/Frameworks/Python.framework/Versions/7.2/lib/python2.7/site-packages/boto-2.3.0-py2.7.egg/boto/dynamodb/item.py", line 45, in __init__
raise DynamoDBItemError('You must supply a hash_key')
boto.dynamodb.exceptions.DynamoDBItemError: BotoClientError: You must supply a hash_key
This makes very little sense to me. I clearly am supplying a hash key. I can't tell what the issue is just by looking at the Boto source. The attribute in question is definitely present in every record (not that that should throw an error).
Any suggestions? Thanks!
Upvotes: 1
Views: 678
Reputation: 45846
Coincidentally, this was just fixed in boto earlier today. See:
https://github.com/boto/boto/issues/656
Upvotes: 2
Reputation: 19361
With the help of a colleague, we've got it figured out. The problem is that attributes_to_get
requires the names of the hash and range keys. So, this works:
>>> x = table.query(hash_key='[email protected]', range_key_condition=BEGINS_WITH("20"),
attributes_to_get=[u'x-start-time', 'user_id', 'session_time'], request_limit=5)
>>> [i for i in x]
[{u'session_time': u'2012/04/18 09:59:20.247 -0400', u'user_id': u'[email protected]',
u'x-start-time': u'2012/04/18 09:59:20.247 -0400'}, ...
This seems like a (minor) Boto issue to me...
Upvotes: 2