Boto DynamoDB 在 table.query 中使用 attributes_to_get 时出错



我有一个使用字符串哈希键和范围键设置的 DynamoDB 数据库。这有效:

>>> x = table.query(hash_key='asdf@asdf.com', range_key_condition=BEGINS_WITH("20"), 
    request_limit=5)
>>> [i for i in x]
[{u'x-entry-page': ...

这没有,我不知道为什么不:

>>> x = table.query(hash_key='asdf@asdf.com', 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 来源,我无法判断问题是什么。有问题的属性肯定存在于每条记录中(不是说应该引发错误)。

有什么建议吗?谢谢!

巧合的是,今天早些时候刚刚在 boto 中修复了这个问题。 看:

https://github.com/boto/boto/issues/656

在同事的帮助下,我们已经弄清楚了。问题是attributes_to_get需要哈希键和范围键的名称。所以,这有效:

>>> x = table.query(hash_key='asdf@asdf.com', 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'asdf@asdf.com', 
    u'x-start-time': u'2012/04/18 09:59:20.247 -0400'}, ...

这对我来说似乎是一个(次要的)Boto问题......

最新更新