gpt4 book ai didi

python - GAE python NDB 投影查询在开发中工作,但在生产中不起作用

转载 作者:行者123 更新时间:2023-11-30 22:03:09 24 4
gpt4 key购买 nike

我一直在碰壁,因为我的 Google App Engine python 项目有一个非常简单的 NDB 投影查询,它在我的本地计算机上运行良好,但在部署到生产环境时却神秘地失败了。

增加了神秘性......作为测试,我在另一个属性上添加了相同的投影,并且它在开发和生产中都有效!有人可以帮忙吗?以下是更多详细信息:

我有以下代表费用的实体:

class Entry(ndb.Model):
datetime = ndb.DateTimeProperty(indexed=True, required=True)
amount = ndb.IntegerProperty(indexed=False, required=True)
payee = ndb.StringProperty(indexed=True, required=True)
comment = ndb.StringProperty(indexed=False)
# ...

稍后在代码中我将对 Entry.payee 进行投影(以获取所有收款人的列表)。作为测试,我还在 Entry.datetime 上添加了投影:

log_msg = '' # For passing debug info to the browser

payeeObjects = Entry.query(ancestor=exp_traq_key(exp_traq_name), projection=[Entry.payee]).fetch()
payees = []
for obj in payeeObjects:
payees.append(obj.payee)
log_msg += '%d payees: %s' % (len(payees), str(payees))

log_msg += ' ------------------- ' # a visual separator

dtObjects = Entry.query(ancestor=exp_traq_key(exp_traq_name), projection=[Entry.datetime]).fetch()
dts = []
for obj in dtObjects:
dts.append(obj.datetime)
log_msg += '%d datetimes: %s' % (len(dts), str(dts))

#...other code, including passing log_msg down to the client

这是开发环境中的输出(请注意控制台中显示了收款人列表和日期时间列表):

enter image description here

这是部署到应用程序引擎时的输出。我无法让它返回收款人列表。即使在 dev 中它返回的列表很好,它仍然返回一个空列表:

enter image description here

我已确保在 GAE 上正确设置了索引:

enter image description here

请帮忙!

<小时/>

2018-12-05更新:我在制作中添加了更多条目,它们被采纳了!请参阅屏幕截图。但较旧的条目仍然没有被归还。 enter image description here

我的第一 react 是数据存储索引需要以某种方式“刷新”,以便它可以“查看”旧条目。但问题是我昨天删除并重新创建了索引,这意味着它应该有旧条目......所以仍然需要帮助来解决这个谜团!

最佳答案

我明白了。该死的,这根本不直观。我希望 GAE 文档在这一点上能更好......

我在生产中的数据存储包含许多以前创建的条目。作为我尝试在 Entry.payee 上进行投影的最新代码的一部分,我必须将 Entry.payee 的定义从未索引更改为索引,如下所示:

payee = ndb.StringProperty(indexed=True, required=True) # Originally was indexed=False

因此,现在数据存储区中的所有条目都将被投影查询忽略,因为收款人上的索引会忽略这些条目。

所以我现在需要做的是以某种方式将所有这些旧实体迁移到 indexed=True

<小时/>

更新 - 以下是我进行此迁移的方法。结果比预期的要简单。

def runPayeeTypeMigration(exp_traq_name):
Entry.query(ancestor=exp_traq_key(exp_traq_name)).fetch()
for entry in entries:
entry.put()

这通过将所有条目读取到更新的数据结构(Entry.payee 被索引=True 的数据结构)并将其写回数据存储区来工作,以便实体现在将被索引。

关于python - GAE python NDB 投影查询在开发中工作,但在生产中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53623464/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com