2012-04-30 49 views
1

我有一個使用字符串散列鍵和範圍鍵設置的DynamoDB數據庫。這工作:Boto DynamoDB在table.query中使用attributes_to_get時出錯

>>> 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': ... 

這不,我想不通爲什麼不:

>>> 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 

這使得很少了意義。我清楚地提供了一個散列鍵。我無法通過查看Boto源文件來判斷問題所在。有問題的屬性肯定存在於每條記錄中(不是那會引發錯誤)。

有什麼建議嗎?謝謝!

回答

2

在同事的幫助下,我們弄清楚了。問題是attributes_to_get需要散列和範圍鍵的名稱。所以,這個工程:

>>> 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'}, ... 

這似乎是一個(小),寶途的問題,我...

+0

巧合的是,[問題進行固定爲3小時前(https://github.com/boto/boto/issues/656)! – Harlan

相關問題