python - 从 GAE 数据存储区删除数据时出现错误 : AttributeError: 'list' object has no attribute 'fetch'

标签 python python-2.7 google-app-engine flash

queries = [query for query in QueryHistory.query().order(-QueryHistory.date)]
if(len(queries) > constants.QUERY_LIMIT_SIZE):
    que = queries[constants.QUERY_LIMIT_SIZE:]
    list_of_keys = que.fetch(keys_only = True)
    ndb.delete_multi(list_of_keys)

从数据存储中删除数据时,我收到 AttributeError: 'list' object has no attribute 'fetch' 错误。如果有人有解决方案请评论。

最佳答案

您的que是一个查询列表,您需要对列表的每个成员调用.fetch(),而不是列表本身。试试这个:

queries = [query for query in QueryHistory.query().order(-QueryHistory.date)]
if(len(queries) > constants.QUERY_LIMIT_SIZE):
    que = queries[constants.QUERY_LIMIT_SIZE:]
    for query in que:
        list_of_keys = query.fetch(keys_only = True)
        ndb.delete_multi(list_of_keys)

关于python - 从 GAE 数据存储区删除数据时出现错误 : AttributeError: 'list' object has no attribute 'fetch' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53506739/

相关文章:

google-cloud-endpoints - 在谷歌应用程序引擎端点中使用@Nullable注释可选参数会删除参数

python - 为什么 lxml 找不到这个类?

python - 你如何从 numpy 数组列表中 'remove' 一个 numpy 数组?

python - 将位串转换为 32 位有符号整数会产生错误的结果

python - 删除字符串之间的空格

python - 查询奇怪的行为。 Google App Engine 数据存储

python - X = X[:, 1]在Python中的含义

python - 在 Python 中反转字符串

Python:展平 XML 文档(删除换行符)

python - 将 Pyramid 和 Mako 与 Google App Engine 结合使用时出现导入错误 : Cannot re-init internal module __main__,