保存ndb LocalStructured实体时的App Engine BadValueError [英] App Engine BadValueError when saving ndb LocalStructured entity

查看:107
本文介绍了保存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.

这篇关于保存ndb LocalStructured实体时的App Engine BadValueError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆