【发布时间】:2023-03-09 14:25:01
【问题描述】:
我有模型
class Foo(ndb.Model):
x = ndb.IntegerProperty()
class Bar(ndb.Model):
foo = ndb.StructuredProperty(Foo, repeated=True)
我最近一直在尝试保存 Bar 实体时,仅在生产中出现此错误:
BadValueError: Expected Foo instance, got Foo(x=100)
我记得不久前看到过这个错误,然后它就消失了。这是什么原因?
【问题讨论】:
-
试试
ndb.KeyProperty(Kind='Foo', repeated=True) -
但是 KeyProperty 不会只保存对 Foo 实体的引用,而不是整个 Foo 实体吗?为什么它比 StructuredProperty 更好?到目前为止,它使用 StructuredProperty 运行良好,所以如果我更改模型,我还必须回填,这会使事情变得复杂。
-
你有不止一个类叫Foo吗?
-
不,我没有。其他人也有类似的问题,但没有提供答案stackoverflow.com/questions/24869911。
-
您是否介意在保存 Bar 对象时准确显示您是如何构建它的?
标签: google-app-engine google-cloud-datastore app-engine-ndb