PynamoDB-如何使用扫描(attributes_to_get = [...])

时间:2019-06-07 17:34:43

标签: python amazon-web-services amazon-dynamodb

我正在使用pynamodb==3.3.3来扫描条件为attributes_to_get的项目,但是出现了一个我无法解决的异常:

  File "/Users/user/Documents/project/script.py", line 250, in filter_writable_snapshots
    existing_snapshots = ItemSnapshot.scan(attributes_to_get=['id'])
  File "/Users/user/Documents/project/venv/lib/python3.7/site-packages/pynamodb/models.py", line 790, in scan
    filters=filters
  File "/Users/users/Documents/project/venv/lib/python3.7/site-packages/pynamodb/models.py", line 1050, in _build_filters
    raise ValueError("Attribute {0} specified for filter does not exist.".format(attr_name))
ValueError: Attribute attributes_to_get specified for filter does not exist.

模型的字段为id

from pynamodb.models import Model
from pynamodb.attributes import UnicodeAttribute

class ItemSnapshot(Model):
    class Meta:
        table_name = 'my_table'

    id = UnicodeAttribute(hash_key=True)
    other_field = UnicodeAttribute()

我正在尝试仅加载id字段。

existing_snapshots = ItemSnapshot.scan(attributes_to_get=['id'])

我在这里做错什么了吗,或者为什么请求崩溃了?跟踪痕迹看起来像是它会尝试找到对我没有任何意义的属性attributes_to_get

我已经检查了类的属性id does exist

1 个答案:

答案 0 :(得分:1)

方法.scan()没有参数attributes_to_get。这在.query().rate_limited_scan()方法中可用。