使用祖先的投影查询会引发错误400

问题描述 投票:0回答:1

通过以下操作将以下数据添加到数据存储中:

    key = ds.key(
            'User', 'alice',
            'id'
        )

    entity = datastore.Entity(
        key=key,
    )

    entity.update({"data": "big amount of information"})
    entity.update({"property_name": "confidential"})
    ds.put(entity)

然后,为了减少资源使用,我尝试使用投影查询来获取较小的属性,而忽略“数据”,这通过执行以下操作确实很大:

    key = ds.key(
        'User', 'alice'
    )
    query = ds.query(ancestor=key)
    query.projection = ["property_name"]

    entities = list()

    for entity in query.fetch():
        entities.append(entity)

    return entities

但我收到此错误:

google.api_core.exceptions.InvalidArgument: 400 Unable to plan or invalidate query.
python google-cloud-datastore gcloud
1个回答
0
投票

祖先查询需要组合索引,即使您要投影单个属性。确保已完成该操作。

© www.soinside.com 2019 - 2024. All rights reserved.