使用谷歌应用引擎模型查询ID



我的数据存储中有一个实体:

In [38]: i1
Out[38]: <my_app.models.Infospot at 0x4255a90>
In [39]: i1.key().id()
Out[39]: 162L

但我无法根据其ID:进行查询

In [41]: Infospot.get_by_id(162L) is None
Out[41]: True
In [45]: Infospot.get(Key.from_path('Infospot', 162L)) is None
Out[45]: True

我做错了什么?

您的Infospot实体似乎是一个子实体。实体由其种类、ID及其所有父实体唯一标识,因此尝试将其作为根实体获取是不可行的。

您可以通过打印i1.key()的值来验证是否存在这种情况;如果它看起来像datastore_types.Key.from_path(u'Something', 123L, 'Infospot', 162L),则表明该实体是Something类型实体的子实体。

最新更新