保存ndb LocalStructured实体时的App Engine BadValueError
问题描述:
我有模型
I have the models
class Foo(ndb.Model):
x = ndb.IntegerProperty()
class Bar(ndb.Model):
foo = ndb.StructuredProperty(Foo, repeated=True)
我最近在尝试保存Bar实体时,只在生产中出现此错误:
I keep getting lately, when trying to save Bar entities, only in production, this error:
BadValueError: Expected Foo instance, got Foo(x=100)
我记得看到这个错误前一阵子,然后消失了。这是什么原因?
I remember seeing this error a while ago, and then it dissapeared. What's the reason for this?
答
问题是我在我保存的文件中使用models.py的相对导入模型,所以不知何故python认为Foo与Foo不同,因为它们在不同的包中。我将模型导入改为绝对导入,现在工作正常。
The problem was I was using relative imports for models.py in the file where I was saving the model, so somehow python thought Foo to be different than Foo because they are in different packages. I changed the models import to be an absolute import, and now it's working fine.