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

查看:17
本文介绍了保存 ndb LocalStructured 实体时出现 App Engine BadValueError的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有模型

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天全站免登陆