【问题标题】:Getting error while deleting data from GAE datastore: AttributeError: 'list' object has no attribute 'fetch'从 GAE 数据存储中删除数据时出错:AttributeError:“list”对象没有属性“fetch”
【发布时间】:2019-04-29 14:39:37
【问题描述】:
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' 错误。如果有人有解决方案,请发表评论。

【问题讨论】:

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


    【解决方案1】:

    您的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)
    

    【讨论】:

    • 你还收到AttributeError吗?
    • list_of_keys = QueryHistory.query().order(-QueryHistory.date).fetch(keys_only=True,offset=constants.QUERY_LIMIT_SIZE) 如果 list_of_keys 不是 None:ndb.delete_multi(list_of_keys) 我有解决了这个问题。我是这样用的。
    • 当然。我专注于您帖子中的错误,而不是其他可能出错的地方:)
    • 感谢您的建议:)
    猜你喜欢
    • 2019-04-11
    • 2011-08-26
    • 1970-01-01
    • 1970-01-01
    • 2019-11-03
    • 2020-12-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多